Revision 5ad06110 libavfilter/vf_pad.c

View differences:

libavfilter/vf_pad.c
30 30
#include "libavutil/avassert.h"
31 31
#include "libavutil/imgutils.h"
32 32
#include "libavutil/parseutils.h"
33

  
34
enum { RED = 0, GREEN, BLUE, ALPHA };
35

  
36
static int fill_line_with_color(uint8_t *line[4], int line_step[4], int w, uint8_t color[4],
37
                                enum PixelFormat pix_fmt, uint8_t rgba_color[4], int *is_packed_rgba)
38
{
39
    uint8_t rgba_map[4] = {0};
40
    int i;
41
    const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[pix_fmt];
42
    int hsub = pix_desc->log2_chroma_w;
43

  
44
    *is_packed_rgba = 1;
45
    switch (pix_fmt) {
46
    case PIX_FMT_ARGB:  rgba_map[ALPHA] = 0; rgba_map[RED  ] = 1; rgba_map[GREEN] = 2; rgba_map[BLUE ] = 3; break;
47
    case PIX_FMT_ABGR:  rgba_map[ALPHA] = 0; rgba_map[BLUE ] = 1; rgba_map[GREEN] = 2; rgba_map[RED  ] = 3; break;
48
    case PIX_FMT_RGBA:
49
    case PIX_FMT_RGB24: rgba_map[RED  ] = 0; rgba_map[GREEN] = 1; rgba_map[BLUE ] = 2; rgba_map[ALPHA] = 3; break;
50
    case PIX_FMT_BGRA:
51
    case PIX_FMT_BGR24: rgba_map[BLUE ] = 0; rgba_map[GREEN] = 1; rgba_map[RED  ] = 2; rgba_map[ALPHA] = 3; break;
52
    default:
53
        *is_packed_rgba = 0;
54
    }
55

  
56
    if (*is_packed_rgba) {
57
        line_step[0] = (av_get_bits_per_pixel(pix_desc))>>3;
58
        for (i = 0; i < 4; i++)
59
            color[rgba_map[i]] = rgba_color[i];
60

  
61
        line[0] = av_malloc(w * line_step[0]);
62
        for (i = 0; i < w; i++)
63
            memcpy(line[0] + i * line_step[0], color, line_step[0]);
64
    } else {
65
        int plane;
66

  
67
        color[RED  ] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]);
68
        color[GREEN] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
69
        color[BLUE ] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
70
        color[ALPHA] = rgba_color[3];
71

  
72
        for (plane = 0; plane < 4; plane++) {
73
            int line_size;
74
            int hsub1 = (plane == 1 || plane == 2) ? hsub : 0;
75

  
76
            line_step[plane] = 1;
77
            line_size = (w >> hsub1) * line_step[plane];
78
            line[plane] = av_malloc(line_size);
79
            memset(line[plane], color[plane], line_size);
80
        }
81
    }
82

  
83
    return 0;
84
}
85

  
86
static void draw_rectangle(AVFilterBufferRef *outpic, uint8_t *line[4], int line_step[4],
87
                           int hsub, int vsub, int x, int y, int w, int h)
88
{
89
    int i, plane;
90
    uint8_t *p;
91

  
92
    for (plane = 0; plane < 4 && outpic->data[plane]; plane++) {
93
        int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
94
        int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
95

  
96
        p = outpic->data[plane] + (y >> vsub1) * outpic->linesize[plane];
97
        for (i = 0; i < (h >> vsub1); i++) {
98
            memcpy(p + (x >> hsub1) * line_step[plane], line[plane], (w >> hsub1) * line_step[plane]);
99
            p += outpic->linesize[plane];
100
        }
101
    }
102
}
103

  
104
static void copy_rectangle(AVFilterBufferRef *outpic,uint8_t *line[4], int line_step[4], int linesize[4],
105
                           int hsub, int vsub, int x, int y, int y2, int w, int h)
106
{
107
    int i, plane;
108
    uint8_t *p;
109

  
110
    for (plane = 0; plane < 4 && outpic->data[plane]; plane++) {
111
        int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
112
        int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
113

  
114
        p = outpic->data[plane] + (y >> vsub1) * outpic->linesize[plane];
115
        for (i = 0; i < (h >> vsub1); i++) {
116
            memcpy(p + (x >> hsub1) * line_step[plane], line[plane] + linesize[plane]*(i+(y2>>vsub1)), (w >> hsub1) * line_step[plane]);
117
            p += outpic->linesize[plane];
118
        }
119
    }
120
}
33
#include "drawutils.h"
121 34

  
122 35
static int query_formats(AVFilterContext *ctx)
123 36
{
......
210 123
    pad->in_h = inlink->h & ~((1 << pad->vsub) - 1);
211 124

  
212 125
    memcpy(rgba_color, pad->color, sizeof(rgba_color));
213
    fill_line_with_color(pad->line, pad->line_step, pad->w, pad->color,
214
                         inlink->format, rgba_color, &is_packed_rgba);
126
    ff_fill_line_with_color(pad->line, pad->line_step, pad->w, pad->color,
127
                            inlink->format, rgba_color, &is_packed_rgba, NULL);
215 128

  
216 129
    av_log(ctx, AV_LOG_INFO, "w:%d h:%d -> w:%d h:%d x:%d y:%d color:0x%02X%02X%02X%02X[%s]\n",
217 130
           inlink->w, inlink->h, pad->w, pad->h, pad->x, pad->y,
......
351 264
    }
352 265

  
353 266
    if (bar_h) {
354
        draw_rectangle(link->dst->outputs[0]->out_buf,
355
                       pad->line, pad->line_step, pad->hsub, pad->vsub,
356
                       0, bar_y, pad->w, bar_h);
267
        ff_draw_rectangle(link->dst->outputs[0]->out_buf->data,
268
                          link->dst->outputs[0]->out_buf->linesize,
269
                          pad->line, pad->line_step, pad->hsub, pad->vsub,
270
                          0, bar_y, pad->w, bar_h);
357 271
        avfilter_draw_slice(link->dst->outputs[0], bar_y, bar_h, slice_dir);
358 272
    }
359 273
}
......
374 288
    draw_send_bar_slice(link, y, h, slice_dir, 1);
375 289

  
376 290
    /* left border */
377
    draw_rectangle(outpic, pad->line, pad->line_step, pad->hsub, pad->vsub,
378
                   0, y, pad->x, h);
291
    ff_draw_rectangle(outpic->data, outpic->linesize, pad->line, pad->line_step,
292
                      pad->hsub, pad->vsub, 0, y, pad->x, h);
379 293

  
380 294
    if(pad->needs_copy){
381
        copy_rectangle(outpic,
382
                       inpic->data, pad->line_step, inpic->linesize, pad->hsub, pad->vsub,
383
                       pad->x, y, y-pad->y, inpic->video->w, h);
295
        ff_copy_rectangle(outpic->data, outpic->linesize,
296
                          inpic->data, inpic->linesize, pad->line_step,
297
                          pad->hsub, pad->vsub,
298
                          pad->x, y, y-pad->y, inpic->video->w, h);
384 299
    }
385 300

  
386 301
    /* right border */
387
    draw_rectangle(outpic, pad->line, pad->line_step, pad->hsub, pad->vsub,
388
                   pad->x + pad->in_w, y, pad->w - pad->x - pad->in_w, h);
302
    ff_draw_rectangle(outpic->data, outpic->linesize,
303
                      pad->line, pad->line_step, pad->hsub, pad->vsub,
304
                      pad->x + pad->in_w, y, pad->w - pad->x - pad->in_w, h);
389 305
    avfilter_draw_slice(link->dst->outputs[0], y, h, slice_dir);
390 306

  
391 307
    draw_send_bar_slice(link, y, h, slice_dir, -1);
......
488 404
        return AVERROR(EINVAL);
489 405

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

  
494 410
    av_log(ctx, AV_LOG_INFO, "w:%d h:%d r:%d/%d color:0x%02x%02x%02x%02x[%s]\n",
495 411
           color->w, color->h, color->time_base.den, color->time_base.num,
......
510 426
    picref->pos                 = 0;
511 427

  
512 428
    avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0));
513
    draw_rectangle(picref,
514
                   color->line, color->line_step, color->hsub, color->vsub,
515
                   0, 0, color->w, color->h);
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);
516 432
    avfilter_draw_slice(link, 0, color->h, 1);
517 433
    avfilter_end_frame(link);
518 434
    avfilter_unref_buffer(picref);

Also available in: Unified diff