+static inline int calc_max_draw(ShowVolumeContext *s, AVFilterLink *outlink, float max)
+{
+ float max_val;
+ if (s->display_scale == LINEAR) {
+ max_val = max;
+ } else { /* log */
+ max_val = av_clipf(0.21 * log10(max) + 1, 0, 1);
+ }
+ if (s->orientation) { /* vertical */
+ return outlink->h - outlink->h * max_val;
+ } else { /* horizontal */
+ return s->w * max_val;
+ }
+}
+
+static inline void calc_persistent_max(ShowVolumeContext *s, float max, int channel)
+{
+ /* update max value for persistent max display */
+ if ((max >= s->max_persistent[channel]) || (s->nb_frames_max_display[channel] >= s->persistent_max_frames)) { /* update max value for display */
+ s->max_persistent[channel] = max;
+ s->nb_frames_max_display[channel] = 0;
+ } else {
+ s->nb_frames_max_display[channel] += 1; /* incremente display frame count */
+ }
+}
+
+static inline void draw_max_line(ShowVolumeContext *s, int max_draw, int channel)
+{
+ int k;
+ if (s->orientation) { /* vertical */
+ uint8_t *dst = s->out->data[0] + max_draw * s->out->linesize[0] + channel * (s->b + s->h) * 4;
+ for (k = 0; k < s->h; k++) {
+ memcpy(dst + k * 4, s->persistant_max_rgba, sizeof(s->persistant_max_rgba));
+ }
+ } else { /* horizontal */
+ for (k = 0; k < s->h; k++) {
+ uint8_t *dst = s->out->data[0] + (channel * s->h + channel * s->b + k) * s->out->linesize[0];
+ memcpy(dst + max_draw * 4, s->persistant_max_rgba, sizeof(s->persistant_max_rgba));
+ }
+ }
+}
+