summaryrefslogtreecommitdiff
path: root/libavfilter/vf_blend.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2021-09-27 19:10:17 +0200
committerPaul B Mahol <onemda@gmail.com>2021-09-27 19:12:48 +0200
commitd7408a786f350d4cd9a338821a4c63a0642eb000 (patch)
tree0285d89037b58c3f28facc5206ad39aaf6f187a4 /libavfilter/vf_blend.c
parentb786bc7433dfe082441a57c1ba9ae9ea47904b78 (diff)
avfilter/vf_blend: refactor similar code
Diffstat (limited to 'libavfilter/vf_blend.c')
-rw-r--r--libavfilter/vf_blend.c93
1 files changed, 27 insertions, 66 deletions
diff --git a/libavfilter/vf_blend.c b/libavfilter/vf_blend.c
index ff06940a66..db315fa86f 100644
--- a/libavfilter/vf_blend.c
+++ b/libavfilter/vf_blend.c
@@ -142,74 +142,35 @@ COPY(bottom, 32)
#undef COPY
-static void blend_normal_8bit(const uint8_t *top, ptrdiff_t top_linesize,
- const uint8_t *bottom, ptrdiff_t bottom_linesize,
- uint8_t *dst, ptrdiff_t dst_linesize,
- ptrdiff_t width, ptrdiff_t height,
- FilterParams *param, double *values, int starty)
-{
- const float opacity = param->opacity;
- int i, j;
-
- for (i = 0; i < height; i++) {
- for (j = 0; j < width; j++) {
- dst[j] = top[j] * opacity + bottom[j] * (1.f - opacity);
- }
- dst += dst_linesize;
- top += top_linesize;
- bottom += bottom_linesize;
- }
+#define BLEND_NORMAL(name, type) \
+static void blend_normal_##name(const uint8_t *_top, ptrdiff_t top_linesize, \
+ const uint8_t *_bottom, ptrdiff_t bottom_linesize,\
+ uint8_t *_dst, ptrdiff_t dst_linesize, \
+ ptrdiff_t width, ptrdiff_t height, \
+ FilterParams *param, double *values, int starty) \
+{ \
+ const type *top = (type*)_top; \
+ const type *bottom = (type*)_bottom; \
+ type *dst = (type*)_dst; \
+ const float opacity = param->opacity; \
+ \
+ dst_linesize /= sizeof(type); \
+ top_linesize /= sizeof(type); \
+ bottom_linesize /= sizeof(type); \
+ \
+ for (int i = 0; i < height; i++) { \
+ for (int j = 0; j < width; j++) { \
+ dst[j] = top[j] * opacity + bottom[j] * (1.f - opacity); \
+ } \
+ dst += dst_linesize; \
+ top += top_linesize; \
+ bottom += bottom_linesize; \
+ } \
}
-static void blend_normal_16bit(const uint8_t *_top, ptrdiff_t top_linesize,
- const uint8_t *_bottom, ptrdiff_t bottom_linesize,
- uint8_t *_dst, ptrdiff_t dst_linesize,
- ptrdiff_t width, ptrdiff_t height,
- FilterParams *param, double *values, int starty)
-{
- const uint16_t *top = (uint16_t*)_top;
- const uint16_t *bottom = (uint16_t*)_bottom;
- uint16_t *dst = (uint16_t*)_dst;
- const float opacity = param->opacity;
- int i, j;
- dst_linesize /= 2;
- top_linesize /= 2;
- bottom_linesize /= 2;
-
- for (i = 0; i < height; i++) {
- for (j = 0; j < width; j++) {
- dst[j] = top[j] * opacity + bottom[j] * (1.f - opacity);
- }
- dst += dst_linesize;
- top += top_linesize;
- bottom += bottom_linesize;
- }
-}
-
-static void blend_normal_32bit(const uint8_t *_top, ptrdiff_t top_linesize,
- const uint8_t *_bottom, ptrdiff_t bottom_linesize,
- uint8_t *_dst, ptrdiff_t dst_linesize,
- ptrdiff_t width, ptrdiff_t height,
- FilterParams *param, double *values, int starty)
-{
- const float *top = (float*)_top;
- const float *bottom = (float*)_bottom;
- float *dst = (float*)_dst;
- const float opacity = param->opacity;
- int i, j;
- dst_linesize /= 4;
- top_linesize /= 4;
- bottom_linesize /= 4;
-
- for (i = 0; i < height; i++) {
- for (j = 0; j < width; j++) {
- dst[j] = top[j] * opacity + bottom[j] * (1.f - opacity);
- }
- dst += dst_linesize;
- top += top_linesize;
- bottom += bottom_linesize;
- }
-}
+BLEND_NORMAL(8bit, uint8_t)
+BLEND_NORMAL(16bit, uint16_t)
+BLEND_NORMAL(32bit, float)
#define DEFINE_BLEND8(name, expr) \
static void blend_## name##_8bit(const uint8_t *top, ptrdiff_t top_linesize, \