Revision c8c0189d libavfilter/vf_pad.c

View differences:

libavfilter/vf_pad.c
53 53
    return 0;
54 54
}
55 55

  
56
#if CONFIG_PAD_FILTER
57

  
58 56
typedef struct {
59 57
    int w, h;               ///< output dimensions, a value of 0 will result in the input size
60 58
    int x, y;               ///< offsets of the input area with respect to the padded area
......
330 328
                                    .config_props     = config_output, },
331 329
                                  { .name = NULL}},
332 330
};
333

  
334
#endif /* CONFIG_PAD_FILTER */
335

  
336
#if CONFIG_COLOR_FILTER
337

  
338
typedef struct {
339
    int w, h;
340
    uint8_t color[4];
341
    AVRational time_base;
342
    uint8_t *line[4];
343
    int      line_step[4];
344
    int hsub, vsub;         ///< chroma subsampling values
345
    uint64_t pts;
346
} ColorContext;
347

  
348
static av_cold int color_init(AVFilterContext *ctx, const char *args, void *opaque)
349
{
350
    ColorContext *color = ctx->priv;
351
    char color_string[128] = "black";
352
    char frame_size  [128] = "320x240";
353
    char frame_rate  [128] = "25";
354
    AVRational frame_rate_q;
355
    int ret;
356

  
357
    if (args)
358
        sscanf(args, "%127[^:]:%127[^:]:%127s", color_string, frame_size, frame_rate);
359

  
360
    if (av_parse_video_size(&color->w, &color->h, frame_size) < 0) {
361
        av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", frame_size);
362
        return AVERROR(EINVAL);
363
    }
364

  
365
    if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0 ||
366
        frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
367
        av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", frame_rate);
368
        return AVERROR(EINVAL);
369
    }
370
    color->time_base.num = frame_rate_q.den;
371
    color->time_base.den = frame_rate_q.num;
372

  
373
    if ((ret = av_parse_color(color->color, color_string, -1, ctx)) < 0)
374
        return ret;
375

  
376
    return 0;
377
}
378

  
379
static av_cold void color_uninit(AVFilterContext *ctx)
380
{
381
    ColorContext *color = ctx->priv;
382
    int i;
383

  
384
    for (i = 0; i < 4; i++) {
385
        av_freep(&color->line[i]);
386
        color->line_step[i] = 0;
387
    }
388
}
389

  
390
static int color_config_props(AVFilterLink *inlink)
391
{
392
    AVFilterContext *ctx = inlink->src;
393
    ColorContext *color = ctx->priv;
394
    uint8_t rgba_color[4];
395
    int is_packed_rgba;
396
    const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format];
397

  
398
    color->hsub = pix_desc->log2_chroma_w;
399
    color->vsub = pix_desc->log2_chroma_h;
400

  
401
    color->w &= ~((1 << color->hsub) - 1);
402
    color->h &= ~((1 << color->vsub) - 1);
403
    if (av_image_check_size(color->w, color->h, 0, ctx) < 0)
404
        return AVERROR(EINVAL);
405

  
406
    memcpy(rgba_color, color->color, sizeof(rgba_color));
407
    ff_fill_line_with_color(color->line, color->line_step, color->w, color->color,
408
                            inlink->format, rgba_color, &is_packed_rgba, NULL);
409

  
410
    av_log(ctx, AV_LOG_INFO, "w:%d h:%d r:%d/%d color:0x%02x%02x%02x%02x[%s]\n",
411
           color->w, color->h, color->time_base.den, color->time_base.num,
412
           color->color[0], color->color[1], color->color[2], color->color[3],
413
           is_packed_rgba ? "rgba" : "yuva");
414
    inlink->w = color->w;
415
    inlink->h = color->h;
416

  
417
    return 0;
418
}
419

  
420
static int color_request_frame(AVFilterLink *link)
421
{
422
    ColorContext *color = link->src->priv;
423
    AVFilterBufferRef *picref = avfilter_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h);
424
    picref->video->pixel_aspect = (AVRational) {1, 1};
425
    picref->pts                 = av_rescale_q(color->pts++, color->time_base, AV_TIME_BASE_Q);
426
    picref->pos                 = 0;
427

  
428
    avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0));
429
    ff_draw_rectangle(picref->data, picref->linesize,
430
                      color->line, color->line_step, color->hsub, color->vsub,
431
                      0, 0, color->w, color->h);
432
    avfilter_draw_slice(link, 0, color->h, 1);
433
    avfilter_end_frame(link);
434
    avfilter_unref_buffer(picref);
435

  
436
    return 0;
437
}
438

  
439
AVFilter avfilter_vsrc_color = {
440
    .name        = "color",
441
    .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input, syntax is: [color[:size[:rate]]]"),
442

  
443
    .priv_size = sizeof(ColorContext),
444
    .init      = color_init,
445
    .uninit    = color_uninit,
446

  
447
    .query_formats = query_formats,
448

  
449
    .inputs    = (AVFilterPad[]) {{ .name = NULL}},
450

  
451
    .outputs   = (AVFilterPad[]) {{ .name            = "default",
452
                                    .type            = AVMEDIA_TYPE_VIDEO,
453
                                    .request_frame   = color_request_frame,
454
                                    .config_props    = color_config_props },
455
                                  { .name = NULL}},
456
};
457

  
458
#endif /* CONFIG_COLOR_FILTER */

Also available in: Unified diff