Browse code

vf_pad: use the name 's' for the pointer to the private context

This is shorter and consistent across filters.

Anton Khirnov authored on 2013/03/19 04:44:36
Showing 1 changed files
... ...
@@ -114,9 +114,9 @@ typedef struct {
114 114
 
115 115
 static av_cold int init(AVFilterContext *ctx)
116 116
 {
117
-    PadContext *pad = ctx->priv;
117
+    PadContext *s = ctx->priv;
118 118
 
119
-    if (av_parse_color(pad->color, pad->color_str, -1, ctx) < 0)
119
+    if (av_parse_color(s->color, s->color_str, -1, ctx) < 0)
120 120
         return AVERROR(EINVAL);
121 121
 
122 122
     return 0;
... ...
@@ -124,27 +124,27 @@ static av_cold int init(AVFilterContext *ctx)
124 124
 
125 125
 static av_cold void uninit(AVFilterContext *ctx)
126 126
 {
127
-    PadContext *pad = ctx->priv;
127
+    PadContext *s = ctx->priv;
128 128
     int i;
129 129
 
130 130
     for (i = 0; i < 4; i++) {
131
-        av_freep(&pad->line[i]);
132
-        pad->line_step[i] = 0;
131
+        av_freep(&s->line[i]);
132
+        s->line_step[i] = 0;
133 133
     }
134 134
 }
135 135
 
136 136
 static int config_input(AVFilterLink *inlink)
137 137
 {
138 138
     AVFilterContext *ctx = inlink->dst;
139
-    PadContext *pad = ctx->priv;
139
+    PadContext *s = ctx->priv;
140 140
     const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
141 141
     uint8_t rgba_color[4];
142 142
     int ret, is_packed_rgba;
143 143
     double var_values[VARS_NB], res;
144 144
     char *expr;
145 145
 
146
-    pad->hsub = pix_desc->log2_chroma_w;
147
-    pad->vsub = pix_desc->log2_chroma_h;
146
+    s->hsub = pix_desc->log2_chroma_w;
147
+    s->vsub = pix_desc->log2_chroma_h;
148 148
 
149 149
     var_values[VAR_PI]    = M_PI;
150 150
     var_values[VAR_PHI]   = M_PHI;
... ...
@@ -154,78 +154,78 @@ static int config_input(AVFilterLink *inlink)
154 154
     var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
155 155
     var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
156 156
     var_values[VAR_A]     = (double) inlink->w / inlink->h;
157
-    var_values[VAR_HSUB]  = 1<<pad->hsub;
158
-    var_values[VAR_VSUB]  = 1<<pad->vsub;
157
+    var_values[VAR_HSUB]  = 1<<s->hsub;
158
+    var_values[VAR_VSUB]  = 1<<s->vsub;
159 159
 
160 160
     /* evaluate width and height */
161
-    av_expr_parse_and_eval(&res, (expr = pad->w_expr),
161
+    av_expr_parse_and_eval(&res, (expr = s->w_expr),
162 162
                            var_names, var_values,
163 163
                            NULL, NULL, NULL, NULL, NULL, 0, ctx);
164
-    pad->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
165
-    if ((ret = av_expr_parse_and_eval(&res, (expr = pad->h_expr),
164
+    s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
165
+    if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
166 166
                                       var_names, var_values,
167 167
                                       NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
168 168
         goto eval_fail;
169
-    pad->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
169
+    s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
170 170
     /* evaluate the width again, as it may depend on the evaluated output height */
171
-    if ((ret = av_expr_parse_and_eval(&res, (expr = pad->w_expr),
171
+    if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
172 172
                                       var_names, var_values,
173 173
                                       NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
174 174
         goto eval_fail;
175
-    pad->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
175
+    s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
176 176
 
177 177
     /* evaluate x and y */
178
-    av_expr_parse_and_eval(&res, (expr = pad->x_expr),
178
+    av_expr_parse_and_eval(&res, (expr = s->x_expr),
179 179
                            var_names, var_values,
180 180
                            NULL, NULL, NULL, NULL, NULL, 0, ctx);
181
-    pad->x = var_values[VAR_X] = res;
182
-    if ((ret = av_expr_parse_and_eval(&res, (expr = pad->y_expr),
181
+    s->x = var_values[VAR_X] = res;
182
+    if ((ret = av_expr_parse_and_eval(&res, (expr = s->y_expr),
183 183
                                       var_names, var_values,
184 184
                                       NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
185 185
         goto eval_fail;
186
-    pad->y = var_values[VAR_Y] = res;
186
+    s->y = var_values[VAR_Y] = res;
187 187
     /* evaluate x again, as it may depend on the evaluated y value */
188
-    if ((ret = av_expr_parse_and_eval(&res, (expr = pad->x_expr),
188
+    if ((ret = av_expr_parse_and_eval(&res, (expr = s->x_expr),
189 189
                                       var_names, var_values,
190 190
                                       NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
191 191
         goto eval_fail;
192
-    pad->x = var_values[VAR_X] = res;
192
+    s->x = var_values[VAR_X] = res;
193 193
 
194 194
     /* sanity check params */
195
-    if (pad->w < 0 || pad->h < 0 || pad->x < 0 || pad->y < 0) {
195
+    if (s->w < 0 || s->h < 0 || s->x < 0 || s->y < 0) {
196 196
         av_log(ctx, AV_LOG_ERROR, "Negative values are not acceptable.\n");
197 197
         return AVERROR(EINVAL);
198 198
     }
199 199
 
200
-    if (!pad->w)
201
-        pad->w = inlink->w;
202
-    if (!pad->h)
203
-        pad->h = inlink->h;
200
+    if (!s->w)
201
+        s->w = inlink->w;
202
+    if (!s->h)
203
+        s->h = inlink->h;
204 204
 
205
-    pad->w &= ~((1 << pad->hsub) - 1);
206
-    pad->h &= ~((1 << pad->vsub) - 1);
207
-    pad->x &= ~((1 << pad->hsub) - 1);
208
-    pad->y &= ~((1 << pad->vsub) - 1);
205
+    s->w &= ~((1 << s->hsub) - 1);
206
+    s->h &= ~((1 << s->vsub) - 1);
207
+    s->x &= ~((1 << s->hsub) - 1);
208
+    s->y &= ~((1 << s->vsub) - 1);
209 209
 
210
-    pad->in_w = inlink->w & ~((1 << pad->hsub) - 1);
211
-    pad->in_h = inlink->h & ~((1 << pad->vsub) - 1);
210
+    s->in_w = inlink->w & ~((1 << s->hsub) - 1);
211
+    s->in_h = inlink->h & ~((1 << s->vsub) - 1);
212 212
 
213
-    memcpy(rgba_color, pad->color, sizeof(rgba_color));
214
-    ff_fill_line_with_color(pad->line, pad->line_step, pad->w, pad->color,
213
+    memcpy(rgba_color, s->color, sizeof(rgba_color));
214
+    ff_fill_line_with_color(s->line, s->line_step, s->w, s->color,
215 215
                             inlink->format, rgba_color, &is_packed_rgba, NULL);
216 216
 
217 217
     av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d x:%d y:%d color:0x%02X%02X%02X%02X[%s]\n",
218
-           inlink->w, inlink->h, pad->w, pad->h, pad->x, pad->y,
219
-           pad->color[0], pad->color[1], pad->color[2], pad->color[3],
218
+           inlink->w, inlink->h, s->w, s->h, s->x, s->y,
219
+           s->color[0], s->color[1], s->color[2], s->color[3],
220 220
            is_packed_rgba ? "rgba" : "yuva");
221 221
 
222
-    if (pad->x <  0 || pad->y <  0                      ||
223
-        pad->w <= 0 || pad->h <= 0                      ||
224
-        (unsigned)pad->x + (unsigned)inlink->w > pad->w ||
225
-        (unsigned)pad->y + (unsigned)inlink->h > pad->h) {
222
+    if (s->x <  0 || s->y <  0                      ||
223
+        s->w <= 0 || s->h <= 0                      ||
224
+        (unsigned)s->x + (unsigned)inlink->w > s->w ||
225
+        (unsigned)s->y + (unsigned)inlink->h > s->h) {
226 226
         av_log(ctx, AV_LOG_ERROR,
227 227
                "Input area %d:%d:%d:%d not within the padded area 0:0:%d:%d or zero-sized\n",
228
-               pad->x, pad->y, pad->x + inlink->w, pad->y + inlink->h, pad->w, pad->h);
228
+               s->x, s->y, s->x + inlink->w, s->y + inlink->h, s->w, s->h);
229 229
         return AVERROR(EINVAL);
230 230
     }
231 231
 
... ...
@@ -240,20 +240,20 @@ eval_fail:
240 240
 
241 241
 static int config_output(AVFilterLink *outlink)
242 242
 {
243
-    PadContext *pad = outlink->src->priv;
243
+    PadContext *s = outlink->src->priv;
244 244
 
245
-    outlink->w = pad->w;
246
-    outlink->h = pad->h;
245
+    outlink->w = s->w;
246
+    outlink->h = s->h;
247 247
     return 0;
248 248
 }
249 249
 
250 250
 static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
251 251
 {
252
-    PadContext *pad = inlink->dst->priv;
252
+    PadContext *s = inlink->dst->priv;
253 253
 
254 254
     AVFrame *frame = ff_get_video_buffer(inlink->dst->outputs[0],
255
-                                         w + (pad->w - pad->in_w),
256
-                                         h + (pad->h - pad->in_h));
255
+                                         w + (s->w - s->in_w),
256
+                                         h + (s->h - s->in_h));
257 257
     int plane;
258 258
 
259 259
     if (!frame)
... ...
@@ -263,11 +263,11 @@ static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
263 263
     frame->height = h;
264 264
 
265 265
     for (plane = 0; plane < 4 && frame->data[plane]; plane++) {
266
-        int hsub = (plane == 1 || plane == 2) ? pad->hsub : 0;
267
-        int vsub = (plane == 1 || plane == 2) ? pad->vsub : 0;
266
+        int hsub = (plane == 1 || plane == 2) ? s->hsub : 0;
267
+        int vsub = (plane == 1 || plane == 2) ? s->vsub : 0;
268 268
 
269
-        frame->data[plane] += (pad->x >> hsub) * pad->line_step[plane] +
270
-            (pad->y >> vsub) * frame->linesize[plane];
269
+        frame->data[plane] += (s->x >> hsub) * s->line_step[plane] +
270
+            (s->y >> vsub) * frame->linesize[plane];
271 271
     }
272 272
 
273 273
     return frame;
... ...
@@ -342,15 +342,15 @@ static int frame_needs_copy(PadContext *s, AVFrame *frame)
342 342
 
343 343
 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
344 344
 {
345
-    PadContext *pad = inlink->dst->priv;
345
+    PadContext *s = inlink->dst->priv;
346 346
     AVFrame *out;
347
-    int needs_copy = frame_needs_copy(pad, in);
347
+    int needs_copy = frame_needs_copy(s, in);
348 348
 
349 349
     if (needs_copy) {
350 350
         av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n");
351 351
         out = ff_get_video_buffer(inlink->dst->outputs[0],
352
-                                  FFMAX(inlink->w, pad->w),
353
-                                  FFMAX(inlink->h, pad->h));
352
+                                  FFMAX(inlink->w, s->w),
353
+                                  FFMAX(inlink->h, s->h));
354 354
         if (!out) {
355 355
             av_frame_free(&in);
356 356
             return AVERROR(ENOMEM);
... ...
@@ -362,45 +362,45 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
362 362
 
363 363
         out = in;
364 364
         for (i = 0; i < FF_ARRAY_ELEMS(out->data) && out->data[i]; i++) {
365
-            int hsub = (i == 1 || i == 2) ? pad->hsub : 0;
366
-            int vsub = (i == 1 || i == 2) ? pad->vsub : 0;
367
-            out->data[i] -= (pad->x >> hsub) * pad->line_step[i] +
368
-                            (pad->y >> vsub) * out->linesize[i];
365
+            int hsub = (i == 1 || i == 2) ? s->hsub : 0;
366
+            int vsub = (i == 1 || i == 2) ? s->vsub : 0;
367
+            out->data[i] -= (s->x >> hsub) * s->line_step[i] +
368
+                            (s->y >> vsub) * out->linesize[i];
369 369
         }
370 370
     }
371 371
 
372 372
     /* top bar */
373
-    if (pad->y) {
373
+    if (s->y) {
374 374
         ff_draw_rectangle(out->data, out->linesize,
375
-                          pad->line, pad->line_step, pad->hsub, pad->vsub,
376
-                          0, 0, pad->w, pad->y);
375
+                          s->line, s->line_step, s->hsub, s->vsub,
376
+                          0, 0, s->w, s->y);
377 377
     }
378 378
 
379 379
     /* bottom bar */
380
-    if (pad->h > pad->y + pad->in_h) {
380
+    if (s->h > s->y + s->in_h) {
381 381
         ff_draw_rectangle(out->data, out->linesize,
382
-                          pad->line, pad->line_step, pad->hsub, pad->vsub,
383
-                          0, pad->y + pad->in_h, pad->w, pad->h - pad->y - pad->in_h);
382
+                          s->line, s->line_step, s->hsub, s->vsub,
383
+                          0, s->y + s->in_h, s->w, s->h - s->y - s->in_h);
384 384
     }
385 385
 
386 386
     /* left border */
387
-    ff_draw_rectangle(out->data, out->linesize, pad->line, pad->line_step,
388
-                      pad->hsub, pad->vsub, 0, pad->y, pad->x, in->height);
387
+    ff_draw_rectangle(out->data, out->linesize, s->line, s->line_step,
388
+                      s->hsub, s->vsub, 0, s->y, s->x, in->height);
389 389
 
390 390
     if (needs_copy) {
391 391
         ff_copy_rectangle(out->data, out->linesize, in->data, in->linesize,
392
-                          pad->line_step, pad->hsub, pad->vsub,
393
-                          pad->x, pad->y, 0, in->width, in->height);
392
+                          s->line_step, s->hsub, s->vsub,
393
+                          s->x, s->y, 0, in->width, in->height);
394 394
     }
395 395
 
396 396
     /* right border */
397 397
     ff_draw_rectangle(out->data, out->linesize,
398
-                      pad->line, pad->line_step, pad->hsub, pad->vsub,
399
-                      pad->x + pad->in_w, pad->y, pad->w - pad->x - pad->in_w,
398
+                      s->line, s->line_step, s->hsub, s->vsub,
399
+                      s->x + s->in_w, s->y, s->w - s->x - s->in_w,
400 400
                       in->height);
401 401
 
402
-    out->width  = pad->w;
403
-    out->height = pad->h;
402
+    out->width  = s->w;
403
+    out->height = s->h;
404 404
 
405 405
     if (in != out)
406 406
         av_frame_free(&in);