Browse code

avfilter/xbr: use function pointers for xbr[234]x

Clément Bœsch authored on 2014/11/16 05:18:18
Showing 1 changed files
... ...
@@ -40,9 +40,12 @@
40 40
 #define RED_BLUE_MASK 0x00FF00FF
41 41
 #define GREEN_MASK    0x0000FF00
42 42
 
43
+typedef void (*xbrfunc_t)(AVFrame *input, AVFrame *output, const uint32_t *r2y);
44
+
43 45
 typedef struct {
44 46
     const AVClass *class;
45 47
     int n;
48
+    xbrfunc_t func;
46 49
     uint32_t rgbtoyuv[1<<24];
47 50
 } XBRContext;
48 51
 
... ...
@@ -392,12 +395,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
392 392
     }
393 393
 
394 394
     av_frame_copy_props(out, in);
395
-    if (xbr->n == 4)
396
-        xbr4x(in, out, r2y);
397
-    else if (xbr->n == 3)
398
-        xbr3x(in, out, r2y);
399
-    else
400
-        xbr2x(in, out, r2y);
395
+    xbr->func(in, out, r2y);
401 396
 
402 397
     out->width  = outlink->w;
403 398
     out->height = outlink->h;
... ...
@@ -409,6 +407,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
409 409
 static int init(AVFilterContext *ctx)
410 410
 {
411 411
     XBRContext *xbr = ctx->priv;
412
+    static const xbrfunc_t xbrfuncs[] = {xbr2x, xbr3x, xbr4x};
413
+
412 414
     uint32_t c;
413 415
     int bg, rg, g;
414 416
 
... ...
@@ -427,6 +427,7 @@ static int init(AVFilterContext *ctx)
427 427
         }
428 428
     }
429 429
 
430
+    xbr->func = xbrfuncs[xbr->n - 2];
430 431
     return 0;
431 432
 }
432 433