Revision 039baa78

View differences:

libavfilter/vf_pad.c
29 29
#include "libavutil/pixdesc.h"
30 30
#include "libavutil/colorspace.h"
31 31

  
32
enum { RED = 0, GREEN, BLUE, ALPHA };
33

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

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

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

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

  
65
        color[RED  ] = RGB_TO_Y(rgba_color[0], rgba_color[1], rgba_color[2]);
66
        color[GREEN] = RGB_TO_U(rgba_color[0], rgba_color[1], rgba_color[2], 0);
67
        color[BLUE ] = RGB_TO_V(rgba_color[0], rgba_color[1], rgba_color[2], 0);
68
        color[ALPHA] = rgba_color[3];
69

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

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

  
81
    return 0;
82
}
83

  
32 84
typedef struct {
33 85
    int w, h;               ///< output dimensions, a value of 0 will result in the input size
34 86
    int x, y;               ///< offsets of the input area with respect to the padded area
......
92 144
    return 0;
93 145
}
94 146

  
95
enum { RED = 0, GREEN, BLUE, ALPHA };
96

  
97 147
static int config_input(AVFilterLink *inlink)
98 148
{
99 149
    AVFilterContext *ctx = inlink->dst;
100 150
    PadContext *pad = ctx->priv;
101 151
    const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format];
102 152
    uint8_t rgba_color[4];
103
    uint8_t rgba_map[4] = {0};
104
    int i, is_packed_rgb = 1;
105

  
106
    switch (inlink->format) {
107
    case PIX_FMT_ARGB:
108
        rgba_map[ALPHA] = 0; rgba_map[RED] = 1; rgba_map[GREEN] = 2; rgba_map[BLUE] = 3;
109
        break;
110
    case PIX_FMT_ABGR:
111
        rgba_map[ALPHA] = 0; rgba_map[BLUE] = 1; rgba_map[GREEN] = 2; rgba_map[RED] = 3;
112
        break;
113
    case PIX_FMT_RGBA:
114
    case PIX_FMT_RGB24:
115
        rgba_map[RED] = 0; rgba_map[GREEN] = 1; rgba_map[BLUE] = 2; rgba_map[ALPHA] = 3;
116
        break;
117
    case PIX_FMT_BGRA:
118
    case PIX_FMT_BGR24:
119
        rgba_map[BLUE] = 0; rgba_map[GREEN] = 1; rgba_map[RED] = 2; rgba_map[ALPHA] = 3;
120
        break;
121
    default:
122
        is_packed_rgb = 0;
123
    }
153
    int is_packed_rgba;
124 154

  
125 155
    pad->hsub = pix_desc->log2_chroma_w;
126 156
    pad->vsub = pix_desc->log2_chroma_h;
......
139 169
    pad->in_h = inlink->h & ~((1 << pad->vsub) - 1);
140 170

  
141 171
    memcpy(rgba_color, pad->color, sizeof(rgba_color));
142
    if (is_packed_rgb) {
143
        pad->line_step[0] = (av_get_bits_per_pixel(&av_pix_fmt_descriptors[inlink->format]))>>3;
144
        for (i = 0; i < 4; i++)
145
            pad->color[rgba_map[i]] = rgba_color[i];
146

  
147
        pad->line[0] = av_malloc(pad->w * pad->line_step[0]);
148
        for (i = 0; i < pad->w; i++)
149
            memcpy(pad->line[0] + i * pad->line_step[0], pad->color, pad->line_step[0]);
150
    } else {
151
        int plane;
152

  
153
        pad->color[0] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]);
154
        pad->color[1] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
155
        pad->color[2] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
156
        pad->color[3] = rgba_color[3];
157

  
158
        for (plane = 0; plane < 4; plane++) {
159
            int line_size;
160
            int hsub = (plane == 1 || plane == 2) ? pad->hsub : 0;
161

  
162
            pad->line_step[plane] = 1;
163
            line_size = (pad->w >> hsub) * pad->line_step[plane];
164
            pad->line[plane] = av_malloc(line_size);
165
            memset(pad->line[plane], pad->color[plane], line_size);
166
        }
167
    }
172
    fill_line_with_color(pad->line, pad->line_step, pad->w, pad->color,
173
                         inlink->format, rgba_color, &is_packed_rgba);
168 174

  
169 175
    av_log(ctx, AV_LOG_INFO, "w:%d h:%d x:%d y:%d color:0x%02X%02X%02X%02X[%s]\n",
170 176
           pad->w, pad->h, pad->x, pad->y,
171 177
           pad->color[0], pad->color[1], pad->color[2], pad->color[3],
172
           is_packed_rgb ? "rgba" : "yuva");
178
           is_packed_rgba ? "rgba" : "yuva");
173 179

  
174 180
    if (pad->x <  0 || pad->y <  0                      ||
175 181
        pad->w <= 0 || pad->h <= 0                      ||

Also available in: Unified diff