[FFmpeg-devel] [PATCH 2/3] avfilter/vf_pseudocolor: use macro for code that repeats
Paul B Mahol
onemda at gmail.com
Thu Jan 28 16:48:12 EET 2021
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
libavfilter/vf_pseudocolor.c | 67 +++++++++---------------------------
1 file changed, 17 insertions(+), 50 deletions(-)
diff --git a/libavfilter/vf_pseudocolor.c b/libavfilter/vf_pseudocolor.c
index 655b2a5111..c06edc1812 100644
--- a/libavfilter/vf_pseudocolor.c
+++ b/libavfilter/vf_pseudocolor.c
@@ -792,6 +792,13 @@ static int query_formats(AVFilterContext *ctx)
return ff_set_common_formats(ctx, fmts_list);
}
+#define PCLIP(v, max, dst, src, x) \
+ if (v >= 0 && v <= max) { \
+ dst[x] = v; \
+ } else { \
+ dst[x] = src[x]; \
+ }
+
static void pseudocolor_filter(int max, int width, int height,
const uint8_t *index,
const uint8_t *src,
@@ -807,11 +814,7 @@ static void pseudocolor_filter(int max, int width, int height,
for (x = 0; x < width; x++) {
int v = lut[index[x]];
- if (v >= 0 && v <= max) {
- dst[x] = v;
- } else {
- dst[x] = src[x];
- }
+ PCLIP(v, max, dst, src, x);
}
index += ilinesize;
src += slinesize;
@@ -834,11 +837,7 @@ static void pseudocolor_filter_11(int max, int width, int height,
for (x = 0; x < width; x++) {
int v = lut[index[(y << 1) * ilinesize + (x << 1)]];
- if (v >= 0 && v <= max) {
- dst[x] = v;
- } else {
- dst[x] = src[x];
- }
+ PCLIP(v, max, dst, src, x);
}
src += slinesize;
dst += dlinesize;
@@ -860,11 +859,7 @@ static void pseudocolor_filter_11d(int max, int width, int height,
for (x = 0; x < width; x++) {
int v = lut[index[(y >> 1) * ilinesize + (x >> 1)]];
- if (v >= 0 && v <= max) {
- dst[x] = v;
- } else {
- dst[x] = src[x];
- }
+ PCLIP(v, max, dst, src, x);
}
src += slinesize;
dst += dlinesize;
@@ -886,11 +881,7 @@ static void pseudocolor_filter_10(int max, int width, int height,
for (x = 0; x < width; x++) {
int v = lut[index[x << 1]];
- if (v >= 0 && v <= max) {
- dst[x] = v;
- } else {
- dst[x] = src[x];
- }
+ PCLIP(v, max, dst, src, x);
}
index += ilinesize;
src += slinesize;
@@ -913,11 +904,7 @@ static void pseudocolor_filter_10d(int max, int width, int height,
for (x = 0; x < width; x++) {
int v = lut[index[x >> 1]];
- if (v >= 0 && v <= max) {
- dst[x] = v;
- } else {
- dst[x] = src[x];
- }
+ PCLIP(v, max, dst, src, x);
}
index += ilinesize;
src += slinesize;
@@ -943,11 +930,7 @@ static void pseudocolor_filter_16(int max, int width, int height,
for (x = 0; x < width; x++) {
int v = lut[index[x]];
- if (v >= 0 && v <= max) {
- dst[x] = v;
- } else {
- dst[x] = src[x];
- }
+ PCLIP(v, max, dst, src, x);
}
index += ilinesize / 2;
src += slinesize / 2;
@@ -973,11 +956,7 @@ static void pseudocolor_filter_16_10(int max, int width, int height,
for (x = 0; x < width; x++) {
int v = lut[index[x << 1]];
- if (v >= 0 && v <= max) {
- dst[x] = v;
- } else {
- dst[x] = src[x];
- }
+ PCLIP(v, max, dst, src, x);
}
index += ilinesize / 2;
src += slinesize / 2;
@@ -1003,11 +982,7 @@ static void pseudocolor_filter_16_10d(int max, int width, int height,
for (x = 0; x < width; x++) {
int v = lut[index[x >> 1]];
- if (v >= 0 && v <= max) {
- dst[x] = v;
- } else {
- dst[x] = src[x];
- }
+ PCLIP(v, max, dst, src, x);
}
index += ilinesize / 2;
src += slinesize / 2;
@@ -1037,11 +1012,7 @@ static void pseudocolor_filter_16_11(int max, int width, int height,
for (x = 0; x < width; x++) {
int v = lut[index[(y << 1) * ilinesize + (x << 1)]];
- if (v >= 0 && v <= max) {
- dst[x] = v;
- } else {
- dst[x] = src[x];
- }
+ PCLIP(v, max, dst, src, x);
}
src += slinesize;
dst += dlinesize;
@@ -1070,11 +1041,7 @@ static void pseudocolor_filter_16_11d(int max, int width, int height,
for (x = 0; x < width; x++) {
int v = lut[index[(y >> 1) * ilinesize + (x >> 1)]];
- if (v >= 0 && v <= max) {
- dst[x] = v;
- } else {
- dst[x] = src[x];
- }
+ PCLIP(v, max, dst, src, x);
}
src += slinesize;
dst += dlinesize;
--
2.17.1
More information about the ffmpeg-devel
mailing list