+static int get_lin_h(int16_t sample, int height)
+{
+ return height/2 - av_rescale(sample, height/2, INT16_MAX);
+}
+
+static int get_lin_h2(int16_t sample, int height)
+{
+ return av_rescale(FFABS(sample), height, INT16_MAX);
+}
+
+static int get_log_h(int16_t sample, int height)
+{
+ return height/2 - FFSIGN(sample) * (log10(1 + FFABS(sample)) * (height/2) / log10(1 + INT16_MAX));
+}
+
+static int get_log_h2(int16_t sample, int height)
+{
+ return log10(1 + FFABS(sample)) * height / log10(1 + INT16_MAX);
+}
+
+static void draw_sample_point_rgba(uint8_t *buf, int height, int linesize,
+ int16_t *prev_y,
+ const uint8_t color[4], int h)
+{
+ if (h >= 0 && h < height) {
+ buf[h * linesize + 0] += color[0];
+ buf[h * linesize + 1] += color[1];
+ buf[h * linesize + 2] += color[2];
+ buf[h * linesize + 3] += color[3];
+ }
+}
+
+static void draw_sample_line_rgba(uint8_t *buf, int height, int linesize,
+ int16_t *prev_y,
+ const uint8_t color[4], int h)
+{
+ int k;
+ int start = height/2;
+ int end = av_clip(h, 0, height-1);
+ if (start > end)
+ FFSWAP(int16_t, start, end);
+ for (k = start; k < end; k++) {
+ buf[k * linesize + 0] += color[0];
+ buf[k * linesize + 1] += color[1];
+ buf[k * linesize + 2] += color[2];
+ buf[k * linesize + 3] += color[3];
+ }
+}
+
+static void draw_sample_p2p_rgba(uint8_t *buf, int height, int linesize,
+ int16_t *prev_y,
+ const uint8_t color[4], int h)
+{
+ int k;
+ if (h >= 0 && h < height) {
+ buf[h * linesize + 0] += color[0];
+ buf[h * linesize + 1] += color[1];
+ buf[h * linesize + 2] += color[2];
+ buf[h * linesize + 3] += color[3];
+ if (*prev_y && h != *prev_y) {
+ int start = *prev_y;
+ int end = av_clip(h, 0, height-1);
+ if (start > end)
+ FFSWAP(int16_t, start, end);
+ for (k = start + 1; k < end; k++) {
+ buf[k * linesize + 0] += color[0];
+ buf[k * linesize + 1] += color[1];
+ buf[k * linesize + 2] += color[2];
+ buf[k * linesize + 3] += color[3];
+ }
+ }
+ }
+ *prev_y = h;
+}
+
+static void draw_sample_cline_rgba(uint8_t *buf, int height, int linesize,
+ int16_t *prev_y,
+ const uint8_t color[4], int h)
+{
+ int k;
+ const int start = (height - h) / 2;
+ const int end = start + h;
+ for (k = start; k < end; k++) {
+ buf[k * linesize + 0] += color[0];
+ buf[k * linesize + 1] += color[1];
+ buf[k * linesize + 2] += color[2];
+ buf[k * linesize + 3] += color[3];
+ }
+}
+
+static void draw_sample_point_gray(uint8_t *buf, int height, int linesize,
+ int16_t *prev_y,
+ const uint8_t color[4], int h)
+{
+ if (h >= 0 && h < height)
+ buf[h * linesize] += color[0];
+}
+
+static void draw_sample_line_gray(uint8_t *buf, int height, int linesize,
+ int16_t *prev_y,
+ const uint8_t color[4], int h)
+{
+ int k;
+ int start = height/2;
+ int end = av_clip(h, 0, height-1);
+ if (start > end)
+ FFSWAP(int16_t, start, end);
+ for (k = start; k < end; k++)
+ buf[k * linesize] += color[0];
+}
+
+static void draw_sample_p2p_gray(uint8_t *buf, int height, int linesize,
+ int16_t *prev_y,
+ const uint8_t color[4], int h)
+{
+ int k;
+ if (h >= 0 && h < height) {
+ buf[h * linesize] += color[0];
+ if (*prev_y && h != *prev_y) {
+ int start = *prev_y;
+ int end = av_clip(h, 0, height-1);
+ if (start > end)
+ FFSWAP(int16_t, start, end);
+ for (k = start + 1; k < end; k++)
+ buf[k * linesize] += color[0];
+ }
+ }
+ *prev_y = h;
+}
+
+static void draw_sample_cline_gray(uint8_t *buf, int height, int linesize,
+ int16_t *prev_y,
+ const uint8_t color[4], int h)
+{
+ int k;
+ const int start = (height - h) / 2;
+ const int end = start + h;
+ for (k = start; k < end; k++)
+ buf[k * linesize] += color[0];
+}
+