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