aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/vf_histogram.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2013-05-19 14:30:42 +0000
committerPaul B Mahol <onemda@gmail.com>2013-05-19 14:30:42 +0000
commit68c4633fa88bfcc36f5b0ae1d34dad47ce928cfe (patch)
treef35b24e82a6e54facbbb81d9b4815c2e75053f26 /libavfilter/vf_histogram.c
parentb154d203b1c280624081a0b52ae27f489ea3333c (diff)
downloadffmpeg-68c4633fa88bfcc36f5b0ae1d34dad47ce928cfe.tar.gz
lavfi/histogram: cache log2 of max_hval
Instead of calculating same value over and over again. Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter/vf_histogram.c')
-rw-r--r--libavfilter/vf_histogram.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/libavfilter/vf_histogram.c b/libavfilter/vf_histogram.c
index 40afe1f327..f17516e77c 100644
--- a/libavfilter/vf_histogram.c
+++ b/libavfilter/vf_histogram.c
@@ -39,7 +39,6 @@ typedef struct HistogramContext {
const AVClass *class; ///< AVClass context for log and options purpose
enum HistogramMode mode;
unsigned histogram[256];
- unsigned max_hval;
int ncomp;
const uint8_t *bg_color;
const uint8_t *fg_color;
@@ -191,6 +190,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
case MODE_LEVELS:
for (k = 0; k < h->ncomp; k++) {
int start = k * (h->level_height + h->scale_height) * h->display_mode;
+ double max_hval_log;
+ unsigned max_hval = 0;
for (i = 0; i < in->height; i++) {
src = in->data[k] + i * in->linesize[k];
@@ -199,15 +200,16 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
}
for (i = 0; i < 256; i++)
- h->max_hval = FFMAX(h->max_hval, h->histogram[i]);
+ max_hval = FFMAX(max_hval, h->histogram[i]);
+ max_hval_log = log2(max_hval + 1);
for (i = 0; i < outlink->w; i++) {
int col_height;
if (h->levels_mode)
- col_height = round(h->level_height * (1. - (log2(h->histogram[i] + 1) / log2(h->max_hval + 1))));
+ col_height = round(h->level_height * (1. - (log2(h->histogram[i] + 1) / max_hval_log)));
else
- col_height = h->level_height - (h->histogram[i] * (int64_t)h->level_height + h->max_hval - 1) / h->max_hval;
+ col_height = h->level_height - (h->histogram[i] * (int64_t)h->level_height + max_hval - 1) / max_hval;
for (j = h->level_height - 1; j >= col_height; j--) {
if (h->display_mode) {
@@ -222,7 +224,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
}
memset(h->histogram, 0, 256 * sizeof(unsigned));
- h->max_hval = 0;
}
break;
case MODE_WAVEFORM: