avfilter/vf_maskedmerge: refactor slice function

This commit is contained in:
Paul B Mahol 2022-02-20 23:52:10 +01:00
parent 954279564a
commit ac0fdac0fc
1 changed files with 30 additions and 43 deletions

View File

@ -137,51 +137,38 @@ static int process_frame(FFFrameSync *fs)
return ff_filter_frame(outlink, out);
}
static void maskedmerge8(const uint8_t *bsrc, const uint8_t *osrc,
const uint8_t *msrc, uint8_t *dst,
ptrdiff_t blinesize, ptrdiff_t olinesize,
ptrdiff_t mlinesize, ptrdiff_t dlinesize,
int w, int h,
int half, int shift)
{
int x, y;
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
dst[x] = bsrc[x] + ((msrc[x] * (osrc[x] - bsrc[x]) + 128) >> 8);
}
dst += dlinesize;
bsrc += blinesize;
osrc += olinesize;
msrc += mlinesize;
}
#define MASKEDMERGE(n, type, half, shift) \
static void maskedmerge##n(const uint8_t *bbsrc, const uint8_t *oosrc, \
const uint8_t *mmsrc, uint8_t *ddst, \
ptrdiff_t blinesize, ptrdiff_t olinesize, \
ptrdiff_t mlinesize, ptrdiff_t dlinesize, \
int w, int h, \
int hhalf, int sshift) \
{ \
const type *bsrc = (const type *)bbsrc; \
const type *osrc = (const type *)oosrc; \
const type *msrc = (const type *)mmsrc; \
type *dst = (type *)ddst; \
\
dlinesize /= sizeof(type); \
blinesize /= sizeof(type); \
olinesize /= sizeof(type); \
mlinesize /= sizeof(type); \
\
for (int y = 0; y < h; y++) { \
for (int x = 0; x < w; x++) { \
dst[x] = bsrc[x] + ((msrc[x] * (osrc[x] - bsrc[x]) + half) >> shift); \
} \
\
dst += dlinesize; \
bsrc += blinesize; \
osrc += olinesize; \
msrc += mlinesize; \
} \
}
static void maskedmerge16(const uint8_t *bbsrc, const uint8_t *oosrc,
const uint8_t *mmsrc, uint8_t *ddst,
ptrdiff_t blinesize, ptrdiff_t olinesize,
ptrdiff_t mlinesize, ptrdiff_t dlinesize,
int w, int h,
int half, int shift)
{
const uint16_t *bsrc = (const uint16_t *)bbsrc;
const uint16_t *osrc = (const uint16_t *)oosrc;
const uint16_t *msrc = (const uint16_t *)mmsrc;
uint16_t *dst = (uint16_t *)ddst;
int x, y;
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
dst[x] = bsrc[x] + ((msrc[x] * (osrc[x] - bsrc[x]) + half) >> shift);
}
dst += dlinesize / 2;
bsrc += blinesize / 2;
osrc += olinesize / 2;
msrc += mlinesize / 2;
}
}
MASKEDMERGE(8, uint8_t, 128, 8)
MASKEDMERGE(16, uint16_t, hhalf, sshift)
static int config_input(AVFilterLink *inlink)
{