From b439ece51cbf4d27bcd05826ed1adc86b9a6ef9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Sun, 26 May 2013 22:32:24 +0200 Subject: [PATCH] lavfi/dctdnoiz: move DC normalization out of loops. Make code slightly faster, simpler, clearer. The filter is still slow as hell, and that change won't cause any visible performance improvement (it still takes more than one minute to process a single 1080p frame on a Core 2 here). --- libavfilter/vf_dctdnoiz.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libavfilter/vf_dctdnoiz.c b/libavfilter/vf_dctdnoiz.c index 8de203c042..92129adafb 100644 --- a/libavfilter/vf_dctdnoiz.c +++ b/libavfilter/vf_dctdnoiz.c @@ -82,9 +82,10 @@ static float *dct_block(DCTdnoizContext *ctx, const float *src, int src_linesize av_dct_calc(ctx->dct, line); column = ctx->tmp_block + y; - for (x = 0; x < BSIZE; x++) { - *line *= x == 0 ? 1. / sqrt(BSIZE) : sqrt(2. / BSIZE); - *column = *line++; + column[0] = line[0] * (1. / sqrt(BSIZE)); + column += BSIZE; + for (x = 1; x < BSIZE; x++) { + *column = line[x] * sqrt(2. / BSIZE); column += BSIZE; } } @@ -92,8 +93,9 @@ static float *dct_block(DCTdnoizContext *ctx, const float *src, int src_linesize column = ctx->tmp_block; for (x = 0; x < BSIZE; x++) { av_dct_calc(ctx->dct, column); - for (y = 0; y < BSIZE; y++) - column[y] *= y == 0 ? 1. / sqrt(BSIZE) : sqrt(2. / BSIZE); + column[0] *= 1. / sqrt(BSIZE); + for (y = 1; y < BSIZE; y++) + column[y] *= sqrt(2. / BSIZE); column += BSIZE; } @@ -111,18 +113,18 @@ static void idct_block(DCTdnoizContext *ctx, float *dst, int dst_linesize) float *tmp = ctx->tmp_block; for (y = 0; y < BSIZE; y++) { - for (x = 0; x < BSIZE; x++) - block[x] *= x == 0 ? sqrt(BSIZE) : 1./sqrt(2. / BSIZE); + block[0] *= sqrt(BSIZE); + for (x = 1; x < BSIZE; x++) + block[x] *= 1./sqrt(2. / BSIZE); av_dct_calc(ctx->idct, block); block += BSIZE; } block = ctx->block; for (y = 0; y < BSIZE; y++) { - for (x = 0; x < BSIZE; x++) { - tmp[x] = block[x*BSIZE + y]; - tmp[x] *= x == 0 ? sqrt(BSIZE) : 1./sqrt(2. / BSIZE); - } + tmp[0] = block[y] * sqrt(BSIZE); + for (x = 1; x < BSIZE; x++) + tmp[x] = block[x*BSIZE + y] * (1./sqrt(2. / BSIZE)); av_dct_calc(ctx->idct, tmp); for (x = 0; x < BSIZE; x++) dst[x*dst_linesize + y] += tmp[x];