History

avfilter/vf_overlay: Hoist calculations out of loop

Also use const where appropriate.

Andreas Rheinhardt committed 1 year ago

Commit 730ffc51 parent a4b34741 file · +14 −22Browse files

Unified · Split

libavfilter/vf_overlay.c+14−22
@@ -470,16 +470,13 @@ static av_always_inline void blend_plane_##depth##_##nbits##bits(AVFilterContext · 469 unmodified lines
470470 int dst_hp = AV_CEIL_RSHIFT(dst_h, vsub); \
471471 int yp = y>>vsub; \
472472 int xp = x>>hsub; \
473− int jmax, j, k, kmax; \
474− int slice_start, slice_end; \
475473 const T max = (1 << nbits) - 1; \
476474 const T mid = (1 << (nbits - 1)); \
477475 \
478− j = FFMAX(-yp, 0); \
479− jmax = FFMIN3(-yp + dst_hp, FFMIN(src_hp, dst_hp), yp + src_hp); \
480− \
481− slice_start = j + (jmax * jobnr) / nb_jobs; \
482− slice_end = j + (jmax * (jobnr+1)) / nb_jobs; \
476+ const int jmin = FFMAX(-yp, 0), jmax = FFMIN3(-yp + dst_hp, FFMIN(src_hp, dst_hp), yp + src_hp); \
477+ const int kmin = FFMAX(-xp, 0), kmax = FFMIN(-xp + dst_wp, src_wp); \
478+ const int slice_start = jmin + (jmax * jobnr) / nb_jobs; \
479+ const int slice_end = jmin + (jmax * (jobnr + 1)) / nb_jobs; \
483480 \
484481 const uint8_t *sp = src->data[i] + (slice_start) * src->linesize[i]; \
485482 uint8_t *dp = dst->data[dst_plane] \
@@ -488,13 +485,12 @@ static av_always_inline void blend_plane_##depth##_##nbits##bits(AVFilterContext · 2 unmodified lines
488485 const uint8_t *ap = src->data[3] + (slice_start << vsub) * src->linesize[3]; \
489486 const uint8_t *dap = main_has_alpha ? dst->data[3] + ((yp + slice_start) << vsub) * dst->linesize[3] : NULL; \
490487 \
491− for (j = slice_start; j < slice_end; j++) { \
492− k = FFMAX(-xp, 0); \
488+ for (int j = slice_start; j < slice_end; ++j) { \
489+ int k = kmin; \
493490 const T *s = (const T *)sp + k; \
494491 const T *a = (const T *)ap + (k << hsub); \
495492 const T *da = main_has_alpha ? (T *)dap + ((xp + k) << hsub) : NULL; \
496493 T *d = (T *)(dp + (xp + k) * dst_step); \
497− kmax = FFMIN(-xp + dst_wp, src_wp); \
498494 \
499495 if (nbits == 8 && ((vsub && j+1 < src_hp) || !vsub) && octx->blend_row[i]) { \
500496 int c = octx->blend_row[i]((uint8_t*)d, (uint8_t*)da, (uint8_t*)s, \
@@ -585,25 +581,21 @@ static inline void alpha_composite_##depth##_##nbits##bits(const AVFrame *src, c · 84 unmodified lines
585581 int jobnr, int nb_jobs) \
586582 { \
587583 T alpha; /* the amount of overlay to blend on to main */ \
588− int i, imax, j, jmax; \
589− int slice_start, slice_end; \
590584 const T max = (1 << nbits) - 1; \
591585 \
592− imax = FFMIN3(-y + dst_h, FFMIN(src_h, dst_h), y + src_h); \
593− i = FFMAX(-y, 0); \
594− \
595− slice_start = i + (imax * jobnr) / nb_jobs; \
596− slice_end = i + ((imax * (jobnr+1)) / nb_jobs); \
586+ const int imin = FFMAX(-y, 0), imax = FFMIN3(-y + dst_h, FFMIN(src_h, dst_h), y + src_h); \
587+ const int jmin = FFMAX(-x, 0), jmax = FFMIN(-x + dst_w, src_w); \
588+ const int slice_start = imin + ( imax * jobnr) / nb_jobs; \
589+ const int slice_end = imin + ((imax * (jobnr + 1)) / nb_jobs); \
597590 \
598591 const uint8_t *sa = src->data[3] + (slice_start) * src->linesize[3]; \
599592 uint8_t *da = dst->data[3] + (y + slice_start) * dst->linesize[3]; \
600593 \
601− for (i = slice_start; i < slice_end; i++) { \
602− j = FFMAX(-x, 0); \
603− const T *s = (const T *)sa + j; \
604− T *d = (T *)da + x + j; \
594+ for (int i = slice_start; i < slice_end; ++i) { \
595+ const T *s = (const T *)sa + jmin; \
596+ T *d = (T *)da + x + jmin; \
605597 \
606− for (jmax = FFMIN(-x + dst_w, src_w); j < jmax; j++) { \
598+ for (int j = jmin; j < jmax; ++j) { \
607599 alpha = *s; \
608600 if (alpha != 0 && alpha != max) { \
609601 uint8_t alpha_d = *d; \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t