aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2023-05-30 16:55:02 +0200
committerPaul B Mahol <onemda@gmail.com>2023-05-30 17:00:30 +0200
commitb01cfdb4ab1900f4908c2659f8c3f107fcd31605 (patch)
tree5cce9c6b62e5f3e3185c3f036a5dcaac9c13d468
parent06e8eedeba3882480b80a9797f6d0d86d72aca12 (diff)
downloadffmpeg-b01cfdb4ab1900f4908c2659f8c3f107fcd31605.tar.gz
avfilter/avf_showwaves: cleanup and simplify some draw calls
-rw-r--r--libavfilter/avf_showwaves.c91
1 files changed, 41 insertions, 50 deletions
diff --git a/libavfilter/avf_showwaves.c b/libavfilter/avf_showwaves.c
index c0b9c8c88e..7597ee2723 100644
--- a/libavfilter/avf_showwaves.c
+++ b/libavfilter/avf_showwaves.c
@@ -28,6 +28,7 @@
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/channel_layout.h"
+#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "avfilter.h"
@@ -241,28 +242,26 @@ static void draw_sample_point_rgba_full(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];
- }
+ uint32_t clr = AV_RN32(color);
+ if (h >= 0 && h < height)
+ AV_WN32(buf + h * linesize, clr);
}
static void draw_sample_line_rgba_scale(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);
+ uint8_t *bufk;
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];
+ bufk = buf + start * linesize;
+ for (int k = start; k < end; k++, bufk += linesize) {
+ bufk[0] += color[0];
+ bufk[1] += color[1];
+ bufk[2] += color[2];
+ bufk[3] += color[3];
}
}
@@ -270,24 +269,21 @@ static void draw_sample_line_rgba_full(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);
+ uint32_t clr = AV_RN32(color);
+ uint8_t *bufk;
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];
- }
+ bufk = buf + start * linesize;
+ for (int k = start; k < end; k++, bufk += linesize)
+ AV_WN32(bufk, clr);
}
static void draw_sample_p2p_rgba_scale(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];
@@ -295,14 +291,16 @@ static void draw_sample_p2p_rgba_scale(uint8_t *buf, int height, int linesize,
buf[h * linesize + 3] += color[3];
if (*prev_y && h != *prev_y) {
int start = *prev_y;
+ uint8_t *bufk;
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];
+ bufk = buf + (start + 1) * linesize;
+ for (int k = start + 1; k < end; k++, bufk += linesize) {
+ bufk[0] += color[0];
+ bufk[1] += color[1];
+ bufk[2] += color[2];
+ bufk[3] += color[3];
}
}
}
@@ -313,23 +311,18 @@ static void draw_sample_p2p_rgba_full(uint8_t *buf, int height, int linesize,
int16_t *prev_y,
const uint8_t color[4], int h)
{
- int k;
+ uint32_t clr = AV_RN32(color);
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];
+ AV_WN32(buf + h * linesize, clr);
if (*prev_y && h != *prev_y) {
int start = *prev_y;
+ uint8_t *bufk;
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];
- }
+ bufk = buf + (start + 1) * linesize;
+ for (int k = start + 1; k < end; k++, bufk += linesize)
+ AV_WN32(bufk, clr);
}
}
*prev_y = h;
@@ -339,29 +332,27 @@ static void draw_sample_cline_rgba_scale(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];
+ uint8_t *bufk = buf + start * linesize;
+ for (int k = start; k < end; k++, bufk += linesize) {
+ bufk[0] += color[0];
+ bufk[1] += color[1];
+ bufk[2] += color[2];
+ bufk[3] += color[3];
}
}
- static void draw_sample_cline_rgba_full(uint8_t *buf, int height, int linesize,
+
+static void draw_sample_cline_rgba_full(uint8_t *buf, int height, int linesize,
int16_t *prev_y,
const uint8_t color[4], int h)
{
- int k;
+ uint32_t clr = AV_RN32(color);
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];
- }
+ uint8_t *bufk = buf + start * linesize;
+ for (int k = start; k < end; k++, bufk += linesize)
+ AV_WN32(bufk, clr);
}
static void draw_sample_point_gray(uint8_t *buf, int height, int linesize,