[FFmpeg-devel] [PATCH 1/2][RFC] lavfi/vf_xbr: Remove function generator macro and function pointer indirection
Alexander Strasser
eclipse7 at gmx.net
Sat Nov 29 03:27:19 CET 2014
It is easier to read and shorter this way.
Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
---
libavfilter/vf_xbr.c | 33 ++++++++++-----------------------
1 file changed, 10 insertions(+), 23 deletions(-)
diff --git a/libavfilter/vf_xbr.c b/libavfilter/vf_xbr.c
index 47e4b76..a67aa13 100644
--- a/libavfilter/vf_xbr.c
+++ b/libavfilter/vf_xbr.c
@@ -38,12 +38,9 @@
#define RED_BLUE_MASK 0x00FF00FF
#define GREEN_MASK 0x0000FF00
-typedef int (*xbrfunc_t)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
-
typedef struct {
const AVClass *class;
int n;
- xbrfunc_t func;
uint32_t rgbtoyuv[1<<24];
} XBRContext;
@@ -216,8 +213,10 @@ static uint32_t pixel_diff(uint32_t x, uint32_t y, const uint32_t *r2y)
} \
} while (0)
-static av_always_inline void xbr_filter(const ThreadData *td, int jobnr, int nb_jobs, int n)
+static int xbr_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
+ XBRContext *xbr = ctx->priv;
+ const ThreadData *td = arg;
int x, y;
const AVFrame *input = td->in;
AVFrame *output = td->out;
@@ -230,7 +229,7 @@ static av_always_inline void xbr_filter(const ThreadData *td, int jobnr, int nb_
for (y = slice_start; y < slice_end; y++) {
- uint32_t *E = (uint32_t *)(output->data[0] + y * output->linesize[0] * n);
+ uint32_t *E = (uint32_t *)(output->data[0] + y * output->linesize[0] * xbr->n);
const uint32_t *sa2 = (uint32_t *)(input->data[0] + y * input->linesize[0] - 8); /* center */
const uint32_t *sa1 = sa2 - (input->linesize[0]>>2); /* up x1 */
const uint32_t *sa0 = sa1 - (input->linesize[0]>>2); /* up x2 */
@@ -282,7 +281,7 @@ static av_always_inline void xbr_filter(const ThreadData *td, int jobnr, int nb_
const uint32_t F4 = sa2[pnext2];
const uint32_t I4 = sa3[pnext2];
- if (n == 2) {
+ if (xbr->n == 2) {
E[0] = E[1] = // 0, 1
E[nl] = E[nl + 1] = PE; // 2, 3
@@ -290,7 +289,7 @@ static av_always_inline void xbr_filter(const ThreadData *td, int jobnr, int nb_
FILT2(PE, PC, PF, PB, PI, PA, PH, PD, PG, I4, A1, I5, H5, A0, D0, B1, C1, F4, C4, G5, G0, nl, 0, nl+1, 1);
FILT2(PE, PA, PB, PD, PC, PG, PF, PH, PI, C1, G0, C4, F4, G5, H5, D0, A0, B1, A1, I4, I5, nl+1, nl, 1, 0);
FILT2(PE, PG, PD, PH, PA, PI, PB, PF, PC, A0, I5, A1, B1, I4, F4, H5, G5, D0, G0, C1, C4, 1, nl+1, 0, nl);
- } else if (n == 3) {
+ } else if (xbr->n == 3) {
E[0] = E[1] = E[2] = // 0, 1, 2
E[nl] = E[nl+1] = E[nl+2] = // 3, 4, 5
E[nl1] = E[nl1+1] = E[nl1+2] = PE; // 6, 7, 8
@@ -299,7 +298,7 @@ static av_always_inline void xbr_filter(const ThreadData *td, int jobnr, int nb_
FILT3(PE, PC, PF, PB, PI, PA, PH, PD, PG, I4, A1, I5, H5, A0, D0, B1, C1, F4, C4, G5, G0, nl1, nl, 0, nl1+1, nl+1, 1, nl1+2, nl+2, 2);
FILT3(PE, PA, PB, PD, PC, PG, PF, PH, PI, C1, G0, C4, F4, G5, H5, D0, A0, B1, A1, I4, I5, nl1+2, nl1+1, nl1, nl+2, nl+1, nl, 2, 1, 0);
FILT3(PE, PG, PD, PH, PA, PI, PB, PF, PC, A0, I5, A1, B1, I4, F4, H5, G5, D0, G0, C1, C4, 2, nl+2, nl1+2, 1, nl+1, nl1+1, 0, nl, nl1);
- } else if (n == 4) {
+ } else if (xbr->n == 4) {
E[0] = E[1] = E[2] = E[3] = // 0, 1, 2, 3
E[nl] = E[nl+1] = E[nl+2] = E[nl+3] = // 4, 5, 6, 7
E[nl1] = E[nl1+1] = E[nl1+2] = E[nl1+3] = // 8, 9, 10, 11
@@ -317,22 +316,12 @@ static av_always_inline void xbr_filter(const ThreadData *td, int jobnr, int nb_
sa3 += 1;
sa4 += 1;
- E += n;
+ E += xbr->n;
}
}
+ return 0;
}
-#define XBR_FUNC(size) \
-static int xbr##size##x(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
-{ \
- xbr_filter(arg, jobnr, nb_jobs, size); \
- return 0; \
-}
-
-XBR_FUNC(2)
-XBR_FUNC(3)
-XBR_FUNC(4)
-
static int config_output(AVFilterLink *outlink)
{
@@ -373,7 +362,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
td.in = in;
td.out = out;
td.rgbtoyuv = xbr->rgbtoyuv;
- ctx->internal->execute(ctx, xbr->func, &td, NULL, FFMIN(inlink->h, ctx->graph->nb_threads));
+ ctx->internal->execute(ctx, xbr_filter, &td, NULL, FFMIN(inlink->h, ctx->graph->nb_threads));
out->width = outlink->w;
out->height = outlink->h;
@@ -385,7 +374,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int init(AVFilterContext *ctx)
{
XBRContext *xbr = ctx->priv;
- static const xbrfunc_t xbrfuncs[] = {xbr2x, xbr3x, xbr4x};
uint32_t c;
int bg, rg, g;
@@ -405,7 +393,6 @@ static int init(AVFilterContext *ctx)
}
}
- xbr->func = xbrfuncs[xbr->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/6b4741e0/attachment.asc>
More information about the ffmpeg-devel
mailing list