avfilter/vf_blend: refactor similar code

This commit is contained in:
Paul B Mahol 2021-09-27 19:10:17 +02:00
parent b786bc7433
commit d7408a786f
1 changed files with 27 additions and 66 deletions

View File

@ -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, \