diff options
author | Muhammad Faiz <mfcc64@gmail.com> | 2015-05-01 12:44:59 +0300 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2015-05-03 12:53:04 +0300 |
commit | a141948a8be73546c1e684c6a1e37a11f2237c76 (patch) | |
tree | e2e1a6602ef8c2e770da3fee00a07bd9bb52a0b3 /libavfilter/avf_showcqt.c | |
parent | 29ef54aa9086d90d9ef2b7b3badd9aa7508f4281 (diff) |
avfilter/avf_showcqt: optimize gamma calculation
benchmark (on intel core2 duo, gcc 4.9.1)
input samples duration 00:03:39.59
command: time -p ffmpeg -f f32le -ac 2 -ar 44100 -i input.pcm \
-filter_complex showcqt=fullhd=0:gamma=$gamma \
-f rawvideo -y /dev/null
gamma previous modified
1 48.49 s 45.38 s
2 49.33 s 48.11 s
3 80.86 s 59.80 s
4 80.84 s 51.25 s
5 80.75 s 61.06 s
6 80.93 s 61.80 s
7 80.03 s 61.56 s
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavfilter/avf_showcqt.c')
-rw-r--r-- | libavfilter/avf_showcqt.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/libavfilter/avf_showcqt.c b/libavfilter/avf_showcqt.c index 8c6ce1f58a..ee76d196dd 100644 --- a/libavfilter/avf_showcqt.c +++ b/libavfilter/avf_showcqt.c @@ -567,8 +567,6 @@ static int plot_cqt(AVFilterLink *inlink) /* calculating cqt */ for (x = 0; x < VIDEO_WIDTH; x++) { int u; - float g = 1.0f / s->gamma; - float g2 = 1.0f / s->gamma2; FFTComplex l = {0,0}; FFTComplex r = {0,0}; @@ -584,10 +582,42 @@ static int plot_cqt(AVFilterLink *inlink) result[x][0] = l.re * l.re + l.im * l.im; result[x][2] = r.re * r.re + r.im * r.im; result[x][1] = 0.5f * (result[x][0] + result[x][2]); - result[x][3] = (g2 == 1.0f) ? result[x][1] : powf(result[x][1], g2); - result[x][0] = 255.0f * powf(FFMIN(1.0f,result[x][0]), g); - result[x][1] = 255.0f * powf(FFMIN(1.0f,result[x][1]), g); - result[x][2] = 255.0f * powf(FFMIN(1.0f,result[x][2]), g); + + if (s->gamma2 == 1.0f) + result[x][3] = result[x][1]; + else if (s->gamma2 = 2.0f) + result[x][3] = sqrtf(result[x][1]); + else if (s->gamma2 = 3.0f) + result[x][3] = cbrtf(result[x][1]); + else if (s->gamma2 = 4.0f) + result[x][3] = sqrtf(sqrtf(result[x][1])); + else + result[x][3] = expf(logf(result[x][1]) * (1.0f / s->gamma2)); + + result[x][0] = FFMIN(1.0f, result[x][0]); + result[x][1] = FFMIN(1.0f, result[x][1]); + result[x][2] = FFMIN(1.0f, result[x][2]); + if (s->gamma == 1.0f) { + result[x][0] = 255.0f * result[x][0]; + result[x][1] = 255.0f * result[x][1]; + result[x][2] = 255.0f * result[x][2]; + } else if (s->gamma == 2.0f) { + result[x][0] = 255.0f * sqrtf(result[x][0]); + result[x][1] = 255.0f * sqrtf(result[x][1]); + result[x][2] = 255.0f * sqrtf(result[x][2]); + } else if (s->gamma == 3.0f) { + result[x][0] = 255.0f * cbrtf(result[x][0]); + result[x][1] = 255.0f * cbrtf(result[x][1]); + result[x][2] = 255.0f * cbrtf(result[x][2]); + } else if (s->gamma == 4.0f) { + result[x][0] = 255.0f * sqrtf(sqrtf(result[x][0])); + result[x][1] = 255.0f * sqrtf(sqrtf(result[x][1])); + result[x][2] = 255.0f * sqrtf(sqrtf(result[x][2])); + } else { + result[x][0] = 255.0f * expf(logf(result[x][0]) * (1.0f / s->gamma)); + result[x][1] = 255.0f * expf(logf(result[x][1]) * (1.0f / s->gamma)); + result[x][2] = 255.0f * expf(logf(result[x][2]) * (1.0f / s->gamma)); + } } if (!s->fullhd) { |