~ubuntu-branches/debian/sid/ffmpeg/sid

« back to all changes in this revision

Viewing changes to libavfilter/vf_blend.c

  • Committer: Package Import Robot
  • Author(s): Andreas Cadhalpun, Fabian Greffrath, Andreas Cadhalpun
  • Date: 2015-09-22 15:15:20 UTC
  • mfrom: (0.1.29)
  • Revision ID: package-import@ubuntu.com-20150922151520-hhmd3in9ykigjvs9
Tags: 7:2.8-1
[ Fabian Greffrath ]
* Pass the --dbg-package=ffmpeg-dbg parameter only to dh_strip.
* Add alternative Depends: libavcodec-ffmpeg-extra56 to libavcodec-dev and
  ffmpeg-dbg to allow for building and debugging with this library installed.

[ Andreas Cadhalpun ]
* Import new major upstream release 2.8.
* Remove the transitional lib*-ffmpeg-dev packages.
* Drop old Breaks on kodi-bin.
* Drop workaround for sparc, which is no Debian architecture anymore.
* Re-enable x265 on alpha, as it's available again.
* Disable unavailable frei0r, opencv and x264 on mips64el.
* Disable libopenjpeg (#787275) and libschroedinger (#787957) decoders.
  (Closes: #786670)
* Disable libdc1394 on sparc64, because it links against the broken due to
  #790560 libudev1.
* Enable libsnappy support.
* Add new symbols.
* Update debian/copyright.
* Update debian/tests/encdec_list.txt.
* Add hls-only-seek-if-there-is-an-offset.patch. (Closes: #798189)
* Add 'Breaks: libavutil-ffmpeg54 (>= 8:0)' to the libraries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
169
169
    av_image_copy_plane(dst, dst_linesize, top, top_linesize, width, end - start);
170
170
}
171
171
 
172
 
#define DEFINE_BLEND(name, expr)                                      \
173
 
static void blend_## name(const uint8_t *top, int top_linesize,       \
174
 
                          const uint8_t *bottom, int bottom_linesize, \
175
 
                          uint8_t *dst, int dst_linesize,             \
176
 
                          int width, int start, int end,              \
177
 
                          FilterParams *param, double *values)        \
178
 
{                                                                     \
179
 
    double opacity = param->opacity;                                  \
180
 
    int i, j;                                                         \
181
 
                                                                      \
182
 
    for (i = start; i < end; i++) {                                   \
183
 
        for (j = 0; j < width; j++) {                                 \
184
 
            dst[j] = top[j] + ((expr) - top[j]) * opacity;            \
185
 
        }                                                             \
186
 
        dst    += dst_linesize;                                       \
187
 
        top    += top_linesize;                                       \
188
 
        bottom += bottom_linesize;                                    \
189
 
    }                                                                 \
 
172
#define DEFINE_BLEND8(name, expr)                                              \
 
173
static void blend_## name##_8bit(const uint8_t *top, int top_linesize,         \
 
174
                                 const uint8_t *bottom, int bottom_linesize,   \
 
175
                                 uint8_t *dst, int dst_linesize,               \
 
176
                                 int width, int start, int end,                \
 
177
                                 FilterParams *param, double *values)          \
 
178
{                                                                              \
 
179
    double opacity = param->opacity;                                           \
 
180
    int i, j;                                                                  \
 
181
                                                                               \
 
182
    for (i = start; i < end; i++) {                                            \
 
183
        for (j = 0; j < width; j++) {                                          \
 
184
            dst[j] = top[j] + ((expr) - top[j]) * opacity;                     \
 
185
        }                                                                      \
 
186
        dst    += dst_linesize;                                                \
 
187
        top    += top_linesize;                                                \
 
188
        bottom += bottom_linesize;                                             \
 
189
    }                                                                          \
 
190
}
 
191
 
 
192
#define DEFINE_BLEND16(name, expr)                                             \
 
193
static void blend_## name##_16bit(const uint8_t *_top, int top_linesize,       \
 
194
                                  const uint8_t *_bottom, int bottom_linesize, \
 
195
                                  uint8_t *_dst, int dst_linesize,             \
 
196
                                  int width, int start, int end,               \
 
197
                                  FilterParams *param, double *values)         \
 
198
{                                                                              \
 
199
    const uint16_t *top = (uint16_t*)_top;                                     \
 
200
    const uint16_t *bottom = (uint16_t*)_bottom;                               \
 
201
    uint16_t *dst = (uint16_t*)_dst;                                           \
 
202
    double opacity = param->opacity;                                           \
 
203
    int i, j;                                                                  \
 
204
    dst_linesize /= 2;                                                         \
 
205
    top_linesize /= 2;                                                         \
 
206
    bottom_linesize /= 2;                                                      \
 
207
                                                                               \
 
208
    for (i = start; i < end; i++) {                                            \
 
209
        for (j = 0; j < width; j++) {                                          \
 
210
            dst[j] = top[j] + ((expr) - top[j]) * opacity;                     \
 
211
        }                                                                      \
 
212
        dst    += dst_linesize;                                                \
 
213
        top    += top_linesize;                                                \
 
214
        bottom += bottom_linesize;                                             \
 
215
    }                                                                          \
190
216
}
191
217
 
192
218
#define A top[j]
197
223
#define BURN(a, b)        (((a) == 0) ? (a) : FFMAX(0, 255 - ((255 - (b)) << 8) / (a)))
198
224
#define DODGE(a, b)       (((a) == 255) ? (a) : FFMIN(255, (((b) << 8) / (255 - (a)))))
199
225
 
200
 
DEFINE_BLEND(addition,   FFMIN(255, A + B))
201
 
DEFINE_BLEND(average,    (A + B) / 2)
202
 
DEFINE_BLEND(subtract,   FFMAX(0, A - B))
203
 
DEFINE_BLEND(multiply,   MULTIPLY(1, A, B))
204
 
DEFINE_BLEND(negation,   255 - FFABS(255 - A - B))
205
 
DEFINE_BLEND(difference, FFABS(A - B))
206
 
DEFINE_BLEND(difference128, av_clip_uint8(128 + A - B))
207
 
DEFINE_BLEND(screen,     SCREEN(1, A, B))
208
 
DEFINE_BLEND(overlay,    (A < 128) ? MULTIPLY(2, A, B) : SCREEN(2, A, B))
209
 
DEFINE_BLEND(hardlight,  (B < 128) ? MULTIPLY(2, B, A) : SCREEN(2, B, A))
210
 
DEFINE_BLEND(hardmix,    (A < (255 - B)) ? 0: 255)
211
 
DEFINE_BLEND(darken,     FFMIN(A, B))
212
 
DEFINE_BLEND(lighten,    FFMAX(A, B))
213
 
DEFINE_BLEND(divide,     av_clip_uint8(((float)A / ((float)B) * 255)))
214
 
DEFINE_BLEND(dodge,      DODGE(A, B))
215
 
DEFINE_BLEND(burn,       BURN(A, B))
216
 
DEFINE_BLEND(softlight,  (A > 127) ? B + (255 - B) * (A - 127.5) / 127.5 * (0.5 - FFABS(B - 127.5) / 255): B - B * ((127.5 - A) / 127.5) * (0.5 - FFABS(B - 127.5)/255))
217
 
DEFINE_BLEND(exclusion,  A + B - 2 * A * B / 255)
218
 
DEFINE_BLEND(pinlight,   (B < 128) ? FFMIN(A, 2 * B) : FFMAX(A, 2 * (B - 128)))
219
 
DEFINE_BLEND(phoenix,    FFMIN(A, B) - FFMAX(A, B) + 255)
220
 
DEFINE_BLEND(reflect,    (B == 255) ? B : FFMIN(255, (A * A / (255 - B))))
221
 
DEFINE_BLEND(glow,       (A == 255) ? A : FFMIN(255, (B * B / (255 - A))))
222
 
DEFINE_BLEND(and,        A & B)
223
 
DEFINE_BLEND(or,         A | B)
224
 
DEFINE_BLEND(xor,        A ^ B)
225
 
DEFINE_BLEND(vividlight, (A < 128) ? BURN(2 * A, B) : DODGE(2 * (A - 128), B))
226
 
DEFINE_BLEND(linearlight,av_clip_uint8((B < 128) ? B + 2 * A - 255 : B + 2 * (A - 128)))
227
 
 
228
 
static void blend_expr(const uint8_t *top, int top_linesize,
229
 
                       const uint8_t *bottom, int bottom_linesize,
230
 
                       uint8_t *dst, int dst_linesize,
231
 
                       int width, int start, int end,
232
 
                       FilterParams *param, double *values)
233
 
{
234
 
    AVExpr *e = param->e;
235
 
    int y, x;
236
 
 
237
 
    for (y = start; y < end; y++) {
238
 
        values[VAR_Y] = y;
239
 
        for (x = 0; x < width; x++) {
240
 
            values[VAR_X]      = x;
241
 
            values[VAR_TOP]    = values[VAR_A] = top[x];
242
 
            values[VAR_BOTTOM] = values[VAR_B] = bottom[x];
243
 
            dst[x] = av_expr_eval(e, values, NULL);
244
 
        }
245
 
        dst    += dst_linesize;
246
 
        top    += top_linesize;
247
 
        bottom += bottom_linesize;
248
 
    }
 
226
DEFINE_BLEND8(addition,   FFMIN(255, A + B))
 
227
DEFINE_BLEND8(average,    (A + B) / 2)
 
228
DEFINE_BLEND8(subtract,   FFMAX(0, A - B))
 
229
DEFINE_BLEND8(multiply,   MULTIPLY(1, A, B))
 
230
DEFINE_BLEND8(negation,   255 - FFABS(255 - A - B))
 
231
DEFINE_BLEND8(difference, FFABS(A - B))
 
232
DEFINE_BLEND8(difference128, av_clip_uint8(128 + A - B))
 
233
DEFINE_BLEND8(screen,     SCREEN(1, A, B))
 
234
DEFINE_BLEND8(overlay,    (A < 128) ? MULTIPLY(2, A, B) : SCREEN(2, A, B))
 
235
DEFINE_BLEND8(hardlight,  (B < 128) ? MULTIPLY(2, B, A) : SCREEN(2, B, A))
 
236
DEFINE_BLEND8(hardmix,    (A < (255 - B)) ? 0: 255)
 
237
DEFINE_BLEND8(darken,     FFMIN(A, B))
 
238
DEFINE_BLEND8(lighten,    FFMAX(A, B))
 
239
DEFINE_BLEND8(divide,     av_clip_uint8(((float)A / ((float)B) * 255)))
 
240
DEFINE_BLEND8(dodge,      DODGE(A, B))
 
241
DEFINE_BLEND8(burn,       BURN(A, B))
 
242
DEFINE_BLEND8(softlight,  (A > 127) ? B + (255 - B) * (A - 127.5) / 127.5 * (0.5 - FFABS(B - 127.5) / 255): B - B * ((127.5 - A) / 127.5) * (0.5 - FFABS(B - 127.5)/255))
 
243
DEFINE_BLEND8(exclusion,  A + B - 2 * A * B / 255)
 
244
DEFINE_BLEND8(pinlight,   (B < 128) ? FFMIN(A, 2 * B) : FFMAX(A, 2 * (B - 128)))
 
245
DEFINE_BLEND8(phoenix,    FFMIN(A, B) - FFMAX(A, B) + 255)
 
246
DEFINE_BLEND8(reflect,    (B == 255) ? B : FFMIN(255, (A * A / (255 - B))))
 
247
DEFINE_BLEND8(glow,       (A == 255) ? A : FFMIN(255, (B * B / (255 - A))))
 
248
DEFINE_BLEND8(and,        A & B)
 
249
DEFINE_BLEND8(or,         A | B)
 
250
DEFINE_BLEND8(xor,        A ^ B)
 
251
DEFINE_BLEND8(vividlight, (A < 128) ? BURN(2 * A, B) : DODGE(2 * (A - 128), B))
 
252
DEFINE_BLEND8(linearlight,av_clip_uint8((B < 128) ? B + 2 * A - 255 : B + 2 * (A - 128)))
 
253
 
 
254
#undef MULTIPLY
 
255
#undef SCREEN
 
256
#undef BURN
 
257
#undef DODGE
 
258
 
 
259
#define MULTIPLY(x, a, b) ((x) * (((a) * (b)) / 65535))
 
260
#define SCREEN(x, a, b)   (65535 - (x) * ((65535 - (a)) * (65535 - (b)) / 65535))
 
261
#define BURN(a, b)        (((a) == 0) ? (a) : FFMAX(0, 65535 - ((65535 - (b)) << 16) / (a)))
 
262
#define DODGE(a, b)       (((a) == 65535) ? (a) : FFMIN(65535, (((b) << 16) / (65535 - (a)))))
 
263
 
 
264
DEFINE_BLEND16(addition,   FFMIN(65535, A + B))
 
265
DEFINE_BLEND16(average,    (A + B) / 2)
 
266
DEFINE_BLEND16(subtract,   FFMAX(0, A - B))
 
267
DEFINE_BLEND16(multiply,   MULTIPLY(1, A, B))
 
268
DEFINE_BLEND16(negation,   65535 - FFABS(65535 - A - B))
 
269
DEFINE_BLEND16(difference, FFABS(A - B))
 
270
DEFINE_BLEND16(difference128, av_clip_uint16(32768 + A - B))
 
271
DEFINE_BLEND16(screen,     SCREEN(1, A, B))
 
272
DEFINE_BLEND16(overlay,    (A < 32768) ? MULTIPLY(2, A, B) : SCREEN(2, A, B))
 
273
DEFINE_BLEND16(hardlight,  (B < 32768) ? MULTIPLY(2, B, A) : SCREEN(2, B, A))
 
274
DEFINE_BLEND16(hardmix,    (A < (65535 - B)) ? 0: 65535)
 
275
DEFINE_BLEND16(darken,     FFMIN(A, B))
 
276
DEFINE_BLEND16(lighten,    FFMAX(A, B))
 
277
DEFINE_BLEND16(divide,     av_clip_uint16(((float)A / ((float)B) * 65535)))
 
278
DEFINE_BLEND16(dodge,      DODGE(A, B))
 
279
DEFINE_BLEND16(burn,       BURN(A, B))
 
280
DEFINE_BLEND16(softlight,  (A > 32767) ? B + (65535 - B) * (A - 32767.5) / 32767.5 * (0.5 - FFABS(B - 32767.5) / 65535): B - B * ((32767.5 - A) / 32767.5) * (0.5 - FFABS(B - 32767.5)/65535))
 
281
DEFINE_BLEND16(exclusion,  A + B - 2 * A * B / 65535)
 
282
DEFINE_BLEND16(pinlight,   (B < 32768) ? FFMIN(A, 2 * B) : FFMAX(A, 2 * (B - 32768)))
 
283
DEFINE_BLEND16(phoenix,    FFMIN(A, B) - FFMAX(A, B) + 65535)
 
284
DEFINE_BLEND16(reflect,    (B == 65535) ? B : FFMIN(65535, (A * A / (65535 - B))))
 
285
DEFINE_BLEND16(glow,       (A == 65535) ? A : FFMIN(65535, (B * B / (65535 - A))))
 
286
DEFINE_BLEND16(and,        A & B)
 
287
DEFINE_BLEND16(or,         A | B)
 
288
DEFINE_BLEND16(xor,        A ^ B)
 
289
DEFINE_BLEND16(vividlight, (A < 32768) ? BURN(2 * A, B) : DODGE(2 * (A - 32768), B))
 
290
DEFINE_BLEND16(linearlight,av_clip_uint16((B < 32768) ? B + 2 * A - 65535 : B + 2 * (A - 32768)))
 
291
 
 
292
#define DEFINE_BLEND_EXPR(type, name, div)                                     \
 
293
static void blend_expr_## name(const uint8_t *_top, int top_linesize,          \
 
294
                               const uint8_t *_bottom, int bottom_linesize,    \
 
295
                               uint8_t *_dst, int dst_linesize,                \
 
296
                               int width, int start, int end,                  \
 
297
                               FilterParams *param, double *values)            \
 
298
{                                                                              \
 
299
    const type *top = (type*)_top;                                             \
 
300
    const type *bottom = (type*)_bottom;                                       \
 
301
    type *dst = (type*)_dst;                                                   \
 
302
    AVExpr *e = param->e;                                                      \
 
303
    int y, x;                                                                  \
 
304
    dst_linesize /= div;                                                       \
 
305
    top_linesize /= div;                                                       \
 
306
    bottom_linesize /= div;                                                    \
 
307
                                                                               \
 
308
    for (y = start; y < end; y++) {                                            \
 
309
        values[VAR_Y] = y;                                                     \
 
310
        for (x = 0; x < width; x++) {                                          \
 
311
            values[VAR_X]      = x;                                            \
 
312
            values[VAR_TOP]    = values[VAR_A] = top[x];                       \
 
313
            values[VAR_BOTTOM] = values[VAR_B] = bottom[x];                    \
 
314
            dst[x] = av_expr_eval(e, values, NULL);                            \
 
315
        }                                                                      \
 
316
        dst    += dst_linesize;                                                \
 
317
        top    += top_linesize;                                                \
 
318
        bottom += bottom_linesize;                                             \
 
319
    }                                                                          \
249
320
}
250
321
 
 
322
DEFINE_BLEND_EXPR(uint8_t, 8bit, 1)
 
323
DEFINE_BLEND_EXPR(uint16_t, 16bit, 2)
 
324
 
251
325
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
252
326
{
253
327
    ThreadData *td = arg;
278
352
static AVFrame *blend_frame(AVFilterContext *ctx, AVFrame *top_buf,
279
353
                            const AVFrame *bottom_buf)
280
354
{
281
 
    BlendContext *b = ctx->priv;
 
355
    BlendContext *s = ctx->priv;
282
356
    AVFilterLink *inlink = ctx->inputs[0];
283
357
    AVFilterLink *outlink = ctx->outputs[0];
284
358
    AVFrame *dst_buf;
289
363
        return top_buf;
290
364
    av_frame_copy_props(dst_buf, top_buf);
291
365
 
292
 
    for (plane = 0; plane < b->nb_planes; plane++) {
293
 
        int hsub = plane == 1 || plane == 2 ? b->hsub : 0;
294
 
        int vsub = plane == 1 || plane == 2 ? b->vsub : 0;
 
366
    for (plane = 0; plane < s->nb_planes; plane++) {
 
367
        int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
 
368
        int vsub = plane == 1 || plane == 2 ? s->vsub : 0;
295
369
        int outw = FF_CEIL_RSHIFT(dst_buf->width,  hsub);
296
370
        int outh = FF_CEIL_RSHIFT(dst_buf->height, vsub);
297
 
        FilterParams *param = &b->params[plane];
 
371
        FilterParams *param = &s->params[plane];
298
372
        ThreadData td = { .top = top_buf, .bottom = bottom_buf, .dst = dst_buf,
299
373
                          .w = outw, .h = outh, .param = param, .plane = plane,
300
374
                          .inlink = inlink };
302
376
        ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outh, ctx->graph->nb_threads));
303
377
    }
304
378
 
305
 
    if (!b->tblend)
 
379
    if (!s->tblend)
306
380
        av_frame_free(&top_buf);
307
381
 
308
382
    return dst_buf;
310
384
 
311
385
static av_cold int init(AVFilterContext *ctx)
312
386
{
313
 
    BlendContext *b = ctx->priv;
314
 
    int ret, plane;
315
 
 
316
 
    b->tblend = !strcmp(ctx->filter->name, "tblend");
317
 
 
318
 
    for (plane = 0; plane < FF_ARRAY_ELEMS(b->params); plane++) {
319
 
        FilterParams *param = &b->params[plane];
320
 
 
321
 
        if (b->all_mode >= 0)
322
 
            param->mode = b->all_mode;
323
 
        if (b->all_opacity < 1)
324
 
            param->opacity = b->all_opacity;
325
 
 
326
 
        switch (param->mode) {
327
 
        case BLEND_ADDITION:   param->blend = blend_addition;   break;
328
 
        case BLEND_AND:        param->blend = blend_and;        break;
329
 
        case BLEND_AVERAGE:    param->blend = blend_average;    break;
330
 
        case BLEND_BURN:       param->blend = blend_burn;       break;
331
 
        case BLEND_DARKEN:     param->blend = blend_darken;     break;
332
 
        case BLEND_DIFFERENCE: param->blend = blend_difference; break;
333
 
        case BLEND_DIFFERENCE128: param->blend = blend_difference128; break;
334
 
        case BLEND_DIVIDE:     param->blend = blend_divide;     break;
335
 
        case BLEND_DODGE:      param->blend = blend_dodge;      break;
336
 
        case BLEND_EXCLUSION:  param->blend = blend_exclusion;  break;
337
 
        case BLEND_GLOW:       param->blend = blend_glow;       break;
338
 
        case BLEND_HARDLIGHT:  param->blend = blend_hardlight;  break;
339
 
        case BLEND_HARDMIX:    param->blend = blend_hardmix;    break;
340
 
        case BLEND_LIGHTEN:    param->blend = blend_lighten;    break;
341
 
        case BLEND_LINEARLIGHT:param->blend = blend_linearlight;break;
342
 
        case BLEND_MULTIPLY:   param->blend = blend_multiply;   break;
343
 
        case BLEND_NEGATION:   param->blend = blend_negation;   break;
344
 
        case BLEND_NORMAL:     param->blend = blend_normal;     break;
345
 
        case BLEND_OR:         param->blend = blend_or;         break;
346
 
        case BLEND_OVERLAY:    param->blend = blend_overlay;    break;
347
 
        case BLEND_PHOENIX:    param->blend = blend_phoenix;    break;
348
 
        case BLEND_PINLIGHT:   param->blend = blend_pinlight;   break;
349
 
        case BLEND_REFLECT:    param->blend = blend_reflect;    break;
350
 
        case BLEND_SCREEN:     param->blend = blend_screen;     break;
351
 
        case BLEND_SOFTLIGHT:  param->blend = blend_softlight;  break;
352
 
        case BLEND_SUBTRACT:   param->blend = blend_subtract;   break;
353
 
        case BLEND_VIVIDLIGHT: param->blend = blend_vividlight; break;
354
 
        case BLEND_XOR:        param->blend = blend_xor;        break;
355
 
        }
356
 
 
357
 
        if (b->all_expr && !param->expr_str) {
358
 
            param->expr_str = av_strdup(b->all_expr);
359
 
            if (!param->expr_str)
360
 
                return AVERROR(ENOMEM);
361
 
        }
362
 
        if (param->expr_str) {
363
 
            ret = av_expr_parse(&param->e, param->expr_str, var_names,
364
 
                                NULL, NULL, NULL, NULL, 0, ctx);
365
 
            if (ret < 0)
366
 
                return ret;
367
 
            param->blend = blend_expr;
368
 
        }
369
 
    }
370
 
 
371
 
    b->dinput.process = blend_frame;
 
387
    BlendContext *s = ctx->priv;
 
388
 
 
389
    s->tblend = !strcmp(ctx->filter->name, "tblend");
 
390
 
 
391
    s->dinput.process = blend_frame;
372
392
    return 0;
373
393
}
374
394
 
378
398
        AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
379
399
        AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ422P,AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ411P,
380
400
        AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
381
 
        AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE
 
401
        AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_GRAY8,
 
402
        AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
 
403
        AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16,
 
404
        AV_PIX_FMT_GBRP16, AV_PIX_FMT_GRAY16,
 
405
        AV_PIX_FMT_NONE
382
406
    };
383
407
 
384
408
    AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
389
413
 
390
414
static av_cold void uninit(AVFilterContext *ctx)
391
415
{
392
 
    BlendContext *b = ctx->priv;
 
416
    BlendContext *s = ctx->priv;
393
417
    int i;
394
418
 
395
 
    ff_dualinput_uninit(&b->dinput);
396
 
    av_frame_free(&b->prev_frame);
 
419
    ff_dualinput_uninit(&s->dinput);
 
420
    av_frame_free(&s->prev_frame);
397
421
 
398
 
    for (i = 0; i < FF_ARRAY_ELEMS(b->params); i++)
399
 
        av_expr_free(b->params[i].e);
 
422
    for (i = 0; i < FF_ARRAY_ELEMS(s->params); i++)
 
423
        av_expr_free(s->params[i].e);
400
424
}
401
425
 
402
 
#if CONFIG_BLEND_FILTER
403
 
 
404
426
static int config_output(AVFilterLink *outlink)
405
427
{
406
428
    AVFilterContext *ctx = outlink->src;
407
429
    AVFilterLink *toplink = ctx->inputs[TOP];
408
 
    AVFilterLink *bottomlink = ctx->inputs[BOTTOM];
409
 
    BlendContext *b = ctx->priv;
 
430
    BlendContext *s = ctx->priv;
410
431
    const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(toplink->format);
411
 
    int ret;
412
 
 
413
 
    if (toplink->format != bottomlink->format) {
414
 
        av_log(ctx, AV_LOG_ERROR, "inputs must be of same pixel format\n");
415
 
        return AVERROR(EINVAL);
416
 
    }
417
 
    if (toplink->w                       != bottomlink->w ||
418
 
        toplink->h                       != bottomlink->h ||
419
 
        toplink->sample_aspect_ratio.num != bottomlink->sample_aspect_ratio.num ||
420
 
        toplink->sample_aspect_ratio.den != bottomlink->sample_aspect_ratio.den) {
421
 
        av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
422
 
               "(size %dx%d, SAR %d:%d) do not match the corresponding "
423
 
               "second input link %s parameters (%dx%d, SAR %d:%d)\n",
424
 
               ctx->input_pads[TOP].name, toplink->w, toplink->h,
425
 
               toplink->sample_aspect_ratio.num,
426
 
               toplink->sample_aspect_ratio.den,
427
 
               ctx->input_pads[BOTTOM].name, bottomlink->w, bottomlink->h,
428
 
               bottomlink->sample_aspect_ratio.num,
429
 
               bottomlink->sample_aspect_ratio.den);
430
 
        return AVERROR(EINVAL);
 
432
    int ret, plane, is_16bit;
 
433
 
 
434
    if (!s->tblend) {
 
435
        AVFilterLink *bottomlink = ctx->inputs[BOTTOM];
 
436
 
 
437
        if (toplink->format != bottomlink->format) {
 
438
            av_log(ctx, AV_LOG_ERROR, "inputs must be of same pixel format\n");
 
439
            return AVERROR(EINVAL);
 
440
        }
 
441
        if (toplink->w                       != bottomlink->w ||
 
442
            toplink->h                       != bottomlink->h ||
 
443
            toplink->sample_aspect_ratio.num != bottomlink->sample_aspect_ratio.num ||
 
444
            toplink->sample_aspect_ratio.den != bottomlink->sample_aspect_ratio.den) {
 
445
            av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
 
446
                   "(size %dx%d, SAR %d:%d) do not match the corresponding "
 
447
                   "second input link %s parameters (%dx%d, SAR %d:%d)\n",
 
448
                   ctx->input_pads[TOP].name, toplink->w, toplink->h,
 
449
                   toplink->sample_aspect_ratio.num,
 
450
                   toplink->sample_aspect_ratio.den,
 
451
                   ctx->input_pads[BOTTOM].name, bottomlink->w, bottomlink->h,
 
452
                   bottomlink->sample_aspect_ratio.num,
 
453
                   bottomlink->sample_aspect_ratio.den);
 
454
            return AVERROR(EINVAL);
 
455
        }
431
456
    }
432
457
 
433
458
    outlink->w = toplink->w;
436
461
    outlink->sample_aspect_ratio = toplink->sample_aspect_ratio;
437
462
    outlink->frame_rate = toplink->frame_rate;
438
463
 
439
 
    b->hsub = pix_desc->log2_chroma_w;
440
 
    b->vsub = pix_desc->log2_chroma_h;
441
 
    b->nb_planes = av_pix_fmt_count_planes(toplink->format);
442
 
 
443
 
    if ((ret = ff_dualinput_init(ctx, &b->dinput)) < 0)
444
 
        return ret;
 
464
    s->hsub = pix_desc->log2_chroma_w;
 
465
    s->vsub = pix_desc->log2_chroma_h;
 
466
 
 
467
    is_16bit = pix_desc->comp[0].depth_minus1 == 15;
 
468
    s->nb_planes = av_pix_fmt_count_planes(toplink->format);
 
469
 
 
470
    if (s->tblend)
 
471
        outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
 
472
    else if ((ret = ff_dualinput_init(ctx, &s->dinput)) < 0)
 
473
            return ret;
 
474
 
 
475
    for (plane = 0; plane < FF_ARRAY_ELEMS(s->params); plane++) {
 
476
        FilterParams *param = &s->params[plane];
 
477
 
 
478
        if (s->all_mode >= 0)
 
479
            param->mode = s->all_mode;
 
480
        if (s->all_opacity < 1)
 
481
            param->opacity = s->all_opacity;
 
482
 
 
483
        switch (param->mode) {
 
484
        case BLEND_ADDITION:   param->blend = is_16bit ? blend_addition_16bit   : blend_addition_8bit;   break;
 
485
        case BLEND_AND:        param->blend = is_16bit ? blend_and_16bit        : blend_and_8bit;        break;
 
486
        case BLEND_AVERAGE:    param->blend = is_16bit ? blend_average_16bit    : blend_average_8bit;    break;
 
487
        case BLEND_BURN:       param->blend = is_16bit ? blend_burn_16bit       : blend_burn_8bit;       break;
 
488
        case BLEND_DARKEN:     param->blend = is_16bit ? blend_darken_16bit     : blend_darken_8bit;     break;
 
489
        case BLEND_DIFFERENCE: param->blend = is_16bit ? blend_difference_16bit : blend_difference_8bit; break;
 
490
        case BLEND_DIFFERENCE128: param->blend = is_16bit ? blend_difference128_16bit: blend_difference128_8bit; break;
 
491
        case BLEND_DIVIDE:     param->blend = is_16bit ? blend_divide_16bit     : blend_divide_8bit;     break;
 
492
        case BLEND_DODGE:      param->blend = is_16bit ? blend_dodge_16bit      : blend_dodge_8bit;      break;
 
493
        case BLEND_EXCLUSION:  param->blend = is_16bit ? blend_exclusion_16bit  : blend_exclusion_8bit;  break;
 
494
        case BLEND_GLOW:       param->blend = is_16bit ? blend_glow_16bit       : blend_glow_8bit;       break;
 
495
        case BLEND_HARDLIGHT:  param->blend = is_16bit ? blend_hardlight_16bit  : blend_hardlight_8bit;  break;
 
496
        case BLEND_HARDMIX:    param->blend = is_16bit ? blend_hardmix_16bit    : blend_hardmix_8bit;    break;
 
497
        case BLEND_LIGHTEN:    param->blend = is_16bit ? blend_lighten_16bit    : blend_lighten_8bit;    break;
 
498
        case BLEND_LINEARLIGHT:param->blend = is_16bit ? blend_linearlight_16bit: blend_linearlight_8bit;break;
 
499
        case BLEND_MULTIPLY:   param->blend = is_16bit ? blend_multiply_16bit   : blend_multiply_8bit;   break;
 
500
        case BLEND_NEGATION:   param->blend = is_16bit ? blend_negation_16bit   : blend_negation_8bit;   break;
 
501
        case BLEND_NORMAL:     param->blend = blend_normal;                                              break;
 
502
        case BLEND_OR:         param->blend = is_16bit ? blend_or_16bit         : blend_or_8bit;         break;
 
503
        case BLEND_OVERLAY:    param->blend = is_16bit ? blend_overlay_16bit    : blend_overlay_8bit;    break;
 
504
        case BLEND_PHOENIX:    param->blend = is_16bit ? blend_phoenix_16bit    : blend_phoenix_8bit;    break;
 
505
        case BLEND_PINLIGHT:   param->blend = is_16bit ? blend_pinlight_16bit   : blend_pinlight_8bit;   break;
 
506
        case BLEND_REFLECT:    param->blend = is_16bit ? blend_reflect_16bit    : blend_reflect_8bit;    break;
 
507
        case BLEND_SCREEN:     param->blend = is_16bit ? blend_screen_16bit     : blend_screen_8bit;     break;
 
508
        case BLEND_SOFTLIGHT:  param->blend = is_16bit ? blend_softlight_16bit  : blend_softlight_8bit;  break;
 
509
        case BLEND_SUBTRACT:   param->blend = is_16bit ? blend_subtract_16bit   : blend_subtract_8bit;   break;
 
510
        case BLEND_VIVIDLIGHT: param->blend = is_16bit ? blend_vividlight_16bit : blend_vividlight_8bit; break;
 
511
        case BLEND_XOR:        param->blend = is_16bit ? blend_xor_16bit        : blend_xor_8bit;        break;
 
512
        }
 
513
 
 
514
        if (s->all_expr && !param->expr_str) {
 
515
            param->expr_str = av_strdup(s->all_expr);
 
516
            if (!param->expr_str)
 
517
                return AVERROR(ENOMEM);
 
518
        }
 
519
        if (param->expr_str) {
 
520
            ret = av_expr_parse(&param->e, param->expr_str, var_names,
 
521
                                NULL, NULL, NULL, NULL, 0, ctx);
 
522
            if (ret < 0)
 
523
                return ret;
 
524
            param->blend = is_16bit? blend_expr_16bit : blend_expr_8bit;
 
525
        }
 
526
    }
445
527
 
446
528
    return 0;
447
529
}
448
530
 
 
531
#if CONFIG_BLEND_FILTER
 
532
 
449
533
static int request_frame(AVFilterLink *outlink)
450
534
{
451
 
    BlendContext *b = outlink->src->priv;
452
 
    return ff_dualinput_request_frame(&b->dinput, outlink);
 
535
    BlendContext *s = outlink->src->priv;
 
536
    return ff_dualinput_request_frame(&s->dinput, outlink);
453
537
}
454
538
 
455
539
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
456
540
{
457
 
    BlendContext *b = inlink->dst->priv;
458
 
    return ff_dualinput_filter_frame(&b->dinput, inlink, buf);
 
541
    BlendContext *s = inlink->dst->priv;
 
542
    return ff_dualinput_filter_frame(&s->dinput, inlink, buf);
459
543
}
460
544
 
461
545
static const AVFilterPad blend_inputs[] = {
498
582
 
499
583
#if CONFIG_TBLEND_FILTER
500
584
 
501
 
static int tblend_config_output(AVFilterLink *outlink)
502
 
{
503
 
    AVFilterContext *ctx = outlink->src;
504
 
    AVFilterLink *inlink = ctx->inputs[0];
505
 
    BlendContext *b = ctx->priv;
506
 
    const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
507
 
 
508
 
    b->hsub = pix_desc->log2_chroma_w;
509
 
    b->vsub = pix_desc->log2_chroma_h;
510
 
    b->nb_planes = av_pix_fmt_count_planes(inlink->format);
511
 
    outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
512
 
 
513
 
    return 0;
514
 
}
515
 
 
516
585
static int tblend_filter_frame(AVFilterLink *inlink, AVFrame *frame)
517
586
{
518
 
    BlendContext *b = inlink->dst->priv;
 
587
    BlendContext *s = inlink->dst->priv;
519
588
    AVFilterLink *outlink = inlink->dst->outputs[0];
520
589
 
521
 
    if (b->prev_frame) {
522
 
        AVFrame *out = blend_frame(inlink->dst, frame, b->prev_frame);
523
 
        av_frame_free(&b->prev_frame);
524
 
        b->prev_frame = frame;
 
590
    if (s->prev_frame) {
 
591
        AVFrame *out = blend_frame(inlink->dst, frame, s->prev_frame);
 
592
        av_frame_free(&s->prev_frame);
 
593
        s->prev_frame = frame;
525
594
        return ff_filter_frame(outlink, out);
526
595
    }
527
 
    b->prev_frame = frame;
 
596
    s->prev_frame = frame;
528
597
    return 0;
529
598
}
530
599
 
548
617
    {
549
618
        .name          = "default",
550
619
        .type          = AVMEDIA_TYPE_VIDEO,
551
 
        .config_props  = tblend_config_output,
 
620
        .config_props  = config_output,
552
621
    },
553
622
    { NULL }
554
623
};