[FFmpeg-devel] [PATCH 2/2][RFC] lavfi/vf_hqx: Remove function generator macro and function pointer indirection

Alexander Strasser eclipse7 at gmx.net
Sat Nov 29 03:27:57 CET 2014


It is easier to read and shorter this way.

Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
---
 libavfilter/vf_hqx.c | 35 +++++++++++------------------------
 1 file changed, 11 insertions(+), 24 deletions(-)

diff --git a/libavfilter/vf_hqx.c b/libavfilter/vf_hqx.c
index 4783381..d3e65e9 100644
--- a/libavfilter/vf_hqx.c
+++ b/libavfilter/vf_hqx.c
@@ -32,12 +32,9 @@
 #include "libavutil/pixdesc.h"
 #include "internal.h"
 
-typedef int (*hqxfunc_t)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
-
 typedef struct {
     const AVClass *class;
     int n;
-    hqxfunc_t func;
     uint32_t rgbtoyuv[1<<24];
 } HQXContext;
 
@@ -378,8 +375,10 @@ static av_always_inline void hq4x_interp_2x2(uint32_t *dst, int dst_linesize,
         *dst11 = w4;
 }
 
-static av_always_inline void hqx_filter(const ThreadData *td, int jobnr, int nb_jobs, int n)
+static av_always_inline int hqx_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 {
+    HQXContext *hqx = ctx->priv;
+    const ThreadData *td = arg;
     int x, y;
     AVFrame *in = td->in, *out = td->out;
     const uint32_t *r2y = td->rgbtoyuv;
@@ -389,7 +388,7 @@ static av_always_inline void hqx_filter(const ThreadData *td, int jobnr, int nb_
     const int slice_end   = (height * (jobnr+1)) / nb_jobs;
     const int dst_linesize = out->linesize[0];
     const int src_linesize =  in->linesize[0];
-    uint8_t       *dst = out->data[0] + slice_start * dst_linesize * n;
+    uint8_t       *dst = out->data[0] + slice_start * dst_linesize * hqx->n;
     const uint8_t *src =  in->data[0] + slice_start * src_linesize;
 
     const int dst32_linesize = dst_linesize >> 2;
@@ -419,18 +418,18 @@ static av_always_inline void hqx_filter(const ThreadData *td, int jobnr, int nb_
                               | (w[4] != w[7] ? (yuv_diff(yuv1, rgb2yuv(r2y, w[7]))) : 0) << 6
                               | (w[4] != w[8] ? (yuv_diff(yuv1, rgb2yuv(r2y, w[8]))) : 0) << 7;
 
-            if (n == 2) {
+            if (hqx->n == 2) {
                 dst32[dst32_linesize*0 + 0] = hq2x_interp_1x1(r2y, pattern, w, 0,1,2,3,4,5,6,7,8);  // 00
                 dst32[dst32_linesize*0 + 1] = hq2x_interp_1x1(r2y, pattern, w, 2,1,0,5,4,3,8,7,6);  // 01 (vert mirrored)
                 dst32[dst32_linesize*1 + 0] = hq2x_interp_1x1(r2y, pattern, w, 6,7,8,3,4,5,0,1,2);  // 10 (horiz mirrored)
                 dst32[dst32_linesize*1 + 1] = hq2x_interp_1x1(r2y, pattern, w, 8,7,6,5,4,3,2,1,0);  // 11 (center mirrored)
-            } else if (n == 3) {
+            } else if (hqx->n == 3) {
                 hq3x_interp_2x1(dst32,                        dst32_linesize, r2y, pattern, w, 0,1, 0,1,2,3,4,5,6,7,8, 0);  // 00 01
                 hq3x_interp_2x1(dst32 + 1,                    dst32_linesize, r2y, pattern, w, 1,3, 2,5,8,1,4,7,0,3,6, 1);  // 02 12 (rotated to the right)
                 hq3x_interp_2x1(dst32 + 1*dst32_linesize,     dst32_linesize, r2y, pattern, w, 2,0, 6,3,0,7,4,1,8,5,2, 1);  // 20 10 (rotated to the left)
                 hq3x_interp_2x1(dst32 + 1*dst32_linesize + 1, dst32_linesize, r2y, pattern, w, 3,2, 8,7,6,5,4,3,2,1,0, 0);  // 22 21 (center mirrored)
                 dst32[dst32_linesize + 1] = w[4];                                                                           // 11
-            } else if (n == 4) {
+            } else if (hqx->n == 4) {
                 hq4x_interp_2x2(dst32,                        dst32_linesize, r2y, pattern, w, 0,1,2,3, 0,1,2,3,4,5,6,7,8); // 00 01 10 11
                 hq4x_interp_2x2(dst32 + 2,                    dst32_linesize, r2y, pattern, w, 1,0,3,2, 2,1,0,5,4,3,8,7,6); // 02 03 12 13 (vert mirrored)
                 hq4x_interp_2x2(dst32 + 2*dst32_linesize,     dst32_linesize, r2y, pattern, w, 2,3,0,1, 6,7,8,3,4,5,0,1,2); // 20 21 30 31 (horiz mirrored)
@@ -440,25 +439,15 @@ static av_always_inline void hqx_filter(const ThreadData *td, int jobnr, int nb_
             }
 
             src32 += 1;
-            dst32 += n;
+            dst32 += hqx->n;
         }
 
         src += src_linesize;
-        dst += dst_linesize * n;
+        dst += dst_linesize * hqx->n;
     }
+    return 0;
 }
 
-#define HQX_FUNC(size) \
-static int hq##size##x(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
-{ \
-    hqx_filter(arg, jobnr, nb_jobs, size); \
-    return 0; \
-}
-
-HQX_FUNC(2)
-HQX_FUNC(3)
-HQX_FUNC(4)
-
 static int query_formats(AVFilterContext *ctx)
 {
     static const enum AVPixelFormat pix_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE};
@@ -498,7 +487,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     td.in = in;
     td.out = out;
     td.rgbtoyuv = hqx->rgbtoyuv;
-    ctx->internal->execute(ctx, hqx->func, &td, NULL, FFMIN(inlink->h, ctx->graph->nb_threads));
+    ctx->internal->execute(ctx, hqx_filter, &td, NULL, FFMIN(inlink->h, ctx->graph->nb_threads));
 
     av_frame_free(&in);
     return ff_filter_frame(outlink, out);
@@ -507,7 +496,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 static av_cold int init(AVFilterContext *ctx)
 {
     HQXContext *hqx = ctx->priv;
-    static const hqxfunc_t hqxfuncs[] = {hq2x, hq3x, hq4x};
 
     uint32_t c;
     int bg, rg, g;
@@ -527,7 +515,6 @@ static av_cold int init(AVFilterContext *ctx)
         }
     }
 
-    hqx->func = hqxfuncs[hqx->n - 2];
     return 0;
 }
 
-- 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141129/0cec2965/attachment.asc>


More information about the ffmpeg-devel mailing list