diff mbox

[FFmpeg-devel,6/7] libavfilter/vf_overlay.c: using the nbits and depth for 8bits and 10bit support

Message ID 20190524093616.74647-6-lance.lmwang@gmail.com
State Superseded
Headers show

Commit Message

Lance Wang May 24, 2019, 9:36 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

---
 libavfilter/vf_overlay.c | 69 +++++++++++++++++++++++++---------------
 1 file changed, 44 insertions(+), 25 deletions(-)

Comments

Michael Niedermayer May 25, 2019, 11:52 a.m. UTC | #1
On Fri, May 24, 2019 at 05:36:15PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> ---
>  libavfilter/vf_overlay.c | 69 +++++++++++++++++++++++++---------------
>  1 file changed, 44 insertions(+), 25 deletions(-)

breaks build

CC	libavfilter/vf_overlay.o
libavfilter/vf_overlay.c: In function ‘blend_plane_8_8bits’:
libavfilter/vf_overlay.c:567:972: warning: unused variable ‘mid’ [-Wunused-variable]
 DEFINE_BLEND_PLANE(8, 8);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ^
libavfilter/vf_overlay.c: In function ‘alpha_composite_8_8bits’:
libavfilter/vf_overlay.c:622:1: error: case label does not reduce to an integer constant
 DEFINE_ALPHA_COMPOSITE(8, 8);
 ^
make: *** [libavfilter/vf_overlay.o] Error 1
make: Target `all' not remade because of errors.


[...]
Lance Wang May 25, 2019, 11:46 p.m. UTC | #2
On Sat, May 25, 2019 at 7:52 PM Michael Niedermayer <michael@niedermayer.cc>
wrote:

> On Fri, May 24, 2019 at 05:36:15PM +0800, lance.lmwang@gmail.com wrote:
> > From: Limin Wang <lance.lmwang@gmail.com>
> >
> > ---
> >  libavfilter/vf_overlay.c | 69 +++++++++++++++++++++++++---------------
> >  1 file changed, 44 insertions(+), 25 deletions(-)
>
> breaks build
>
> CC      libavfilter/vf_overlay.o
> libavfilter/vf_overlay.c: In function ‘blend_plane_8_8bits’:
> libavfilter/vf_overlay.c:567:972: warning: unused variable ‘mid’
> [-Wunused-variable]
>  DEFINE_BLEND_PLANE(8, 8);
>
>
>
>
>
>
>
>
>
>
>
>
>                                                               ^
> libavfilter/vf_overlay.c: In function ‘alpha_composite_8_8bits’:
> libavfilter/vf_overlay.c:622:1: error: case label does not reduce to an
> integer constant
>  DEFINE_ALPHA_COMPOSITE(8, 8);
>  ^
> make: *** [libavfilter/vf_overlay.o] Error 1
> make: Target `all' not remade because of errors.
>
>
>
Sorry, I have tested with other system and fix the build issue now. Please
help to check the new version patch. It's OK with Mac and CentOS linux
system.



> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> If a bugfix only changes things apparently unrelated to the bug with no
> further explanation, that is a good sign that the bugfix is wrong.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox

Patch

diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index ee51a54659..8376494efc 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -464,22 +464,26 @@  static av_always_inline void blend_plane_##depth##_##nbits##bits(AVFilterContext
     int dst_hp = AV_CEIL_RSHIFT(dst_h, vsub);                                                                          \
     int yp = y>>vsub;                                                                                                  \
     int xp = x>>hsub;                                                                                                  \
-    uint8_t *s, *sp, *d, *dp, *dap, *a, *da, *ap;                                                                      \
+    uint##depth##_t *s, *sp, *d, *dp, *dap, *a, *da, *ap;                                                              \
     int jmax, j, k, kmax;                                                                                              \
     int slice_start, slice_end;                                                                                        \
+    const int max = (1 << nbits) - 1;                                                                                  \
+    const int mid = (1 << (nbits -1)) ;                                                                                \
+    int bytes = depth / 8;                                                                                             \
                                                                                                                        \
+    dst_step /= bytes;                                                                                                 \
     j = FFMAX(-yp, 0);                                                                                                 \
     jmax = FFMIN3(-yp + dst_hp, FFMIN(src_hp, dst_hp), yp + src_hp);                                                   \
                                                                                                                        \
     slice_start = j + (jmax * jobnr) / nb_jobs;                                                                        \
     slice_end = j + (jmax * (jobnr+1)) / nb_jobs;                                                                      \
                                                                                                                        \
-    sp = src->data[i] + (slice_start) * src->linesize[i];                                                              \
-    dp = dst->data[dst_plane]                                                                                          \
+    sp = (uint##depth##_t *)(src->data[i] + (slice_start) * src->linesize[i]);                                         \
+    dp = (uint##depth##_t *)(dst->data[dst_plane]                                                                      \
                       + (yp + slice_start) * dst->linesize[dst_plane]                                                  \
-                      + dst_offset;                                                                                    \
-    ap = src->data[3] + (slice_start << vsub) * src->linesize[3];                                                      \
-    dap = dst->data[3] + ((yp + slice_start) << vsub) * dst->linesize[3];                                              \
+                      + dst_offset);                                                                                   \
+    ap = (uint##depth##_t *)(src->data[3] + (slice_start << vsub) * src->linesize[3]);                                 \
+    dap = (uint##depth##_t *)(dst->data[3] + ((yp + slice_start) << vsub) * dst->linesize[3]);                         \
                                                                                                                        \
     for (j = slice_start; j < slice_end; j++) {                                                                        \
         k = FFMAX(-xp, 0);                                                                                             \
@@ -489,7 +493,7 @@  static av_always_inline void blend_plane_##depth##_##nbits##bits(AVFilterContext
         da = dap + ((xp+k) << hsub);                                                                                   \
         kmax = FFMIN(-xp + dst_wp, src_wp);                                                                            \
                                                                                                                        \
-        if (((vsub && j+1 < src_hp) || !vsub) && octx->blend_row[i]) {                                                 \
+        if (nbits == 8 && ((vsub && j+1 < src_hp) || !vsub) && octx->blend_row[i]) {                                   \
             int c = octx->blend_row[i](d, da, s, a, kmax - k, src->linesize[3]);                                       \
                                                                                                                        \
             s += c;                                                                                                    \
@@ -515,7 +519,7 @@  static av_always_inline void blend_plane_##depth##_##nbits##bits(AVFilterContext
                 alpha = a[0];                                                                                          \
             /* if the main channel has an alpha channel, alpha has to be calculated */                                 \
             /* to create an un-premultiplied (straight) alpha value */                                                 \
-            if (main_has_alpha && alpha != 0 && alpha != 255) {                                                        \
+            if (main_has_alpha && alpha != 0 && alpha != max) {                                                        \
                 /* average alpha for color components, improve quality */                                              \
                 uint8_t alpha_d;                                                                                       \
                 if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {                                                    \
@@ -532,22 +536,32 @@  static av_always_inline void blend_plane_##depth##_##nbits##bits(AVFilterContext
                 alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d);                                                           \
             }                                                                                                          \
             if (straight) {                                                                                            \
-                *d = FAST_DIV255(*d * (255 - alpha) + *s * alpha);                                                     \
-            } else {                                                                                                   \
-                if (i && yuv)                                                                                          \
-                    *d = av_clip(FAST_DIV255((*d - 128) * (255 - alpha)) + *s - 128, -128, 128) + 128;                 \
+                if (nbits > 8)                                                                                         \
+                   *d = (*d * (max - alpha) + *s * alpha) / max;                                                       \
                 else                                                                                                   \
-                    *d = FFMIN(FAST_DIV255(*d * (255 - alpha)) + *s, 255);                                             \
+                    *d = FAST_DIV255(*d * (255 - alpha) + *s * alpha);                                                 \
+            } else {                                                                                                   \
+                if (nbits > 8) {                                                                                       \
+                    if (i && yuv)                                                                                      \
+                        *d = av_clip((*d * (max - alpha) + *s * alpha) / max + *s - 128, -128, 128) + 128;             \
+                    else                                                                                               \
+                        *d = FFMIN((*d * (max - alpha) + *s * alpha) / max + *s, 255);                                 \
+                } else {                                                                                               \
+                    if (i && yuv)                                                                                      \
+                        *d = av_clip(FAST_DIV255((*d - 128) * (255 - alpha)) + *s - 128, -128, 128) + 128;             \
+                    else                                                                                               \
+                        *d = FFMIN(FAST_DIV255(*d * (255 - alpha)) + *s, 255);                                         \
+                }                                                                                                      \
             }                                                                                                          \
             s++;                                                                                                       \
             d += dst_step;                                                                                             \
             da += 1 << hsub;                                                                                           \
             a += 1 << hsub;                                                                                            \
         }                                                                                                              \
-        dp += dst->linesize[dst_plane];                                                                                \
-        sp += src->linesize[i];                                                                                        \
-        ap += (1 << vsub) * src->linesize[3];                                                                          \
-        dap += (1 << vsub) * dst->linesize[3];                                                                         \
+        dp += dst->linesize[dst_plane] / bytes;                                                                        \
+        sp += src->linesize[i] / bytes;                                                                                \
+        ap += (1 << vsub) * src->linesize[3] / bytes;                                                                  \
+        dap += (1 << vsub) * dst->linesize[3] / bytes;                                                                 \
     }                                                                                                                  \
 }
 DEFINE_BLEND_PLANE(8, 8);
@@ -559,18 +573,20 @@  static inline void alpha_composite_##depth##_##nbits##bits(const AVFrame *src, c
                                    int x, int y,                                                                       \
                                    int jobnr, int nb_jobs)                                                             \
 {                                                                                                                      \
-    uint8_t alpha;          /* the amount of overlay to blend on to main */                                            \
-    uint8_t *s, *sa, *d, *da;                                                                                          \
+    uint##depth##_t alpha;          /* the amount of overlay to blend on to main */                                    \
+    uint##depth##_t *s, *sa, *d, *da;                                                                                  \
     int i, imax, j, jmax;                                                                                              \
     int slice_start, slice_end;                                                                                        \
+    const int max = (1 << nbits) - 1;                                                                                  \
+    int bytes = depth / 8;                                                                                             \
                                                                                                                        \
     imax = FFMIN(-y + dst_h, src_h);                                                                                   \
     slice_start = (imax * jobnr) / nb_jobs;                                                                            \
     slice_end = ((imax * (jobnr+1)) / nb_jobs);                                                                        \
                                                                                                                        \
     i = FFMAX(-y, 0);                                                                                                  \
-    sa = src->data[3] + (i + slice_start) * src->linesize[3];                                                          \
-    da = dst->data[3] + (y + i + slice_start) * dst->linesize[3];                                                      \
+    sa = (uint##depth##_t *)(src->data[3] + (i + slice_start) * src->linesize[3]);                                     \
+    da = (uint##depth##_t *)(dst->data[3] + (y + i + slice_start) * dst->linesize[3]);                                 \
                                                                                                                        \
     for (i = i + slice_start; i < slice_end; i++) {                                                                    \
         j = FFMAX(-x, 0);                                                                                              \
@@ -586,18 +602,21 @@  static inline void alpha_composite_##depth##_##nbits##bits(const AVFrame *src, c
             switch (alpha) {                                                                                           \
             case 0:                                                                                                    \
                 break;                                                                                                 \
-            case 255:                                                                                                  \
+            case max:                                                                                                  \
                 *d = *s;                                                                                               \
                 break;                                                                                                 \
             default:                                                                                                   \
                 /* apply alpha compositing: main_alpha += (1-main_alpha) * overlay_alpha */                            \
-                *d += FAST_DIV255((255 - *d) * *s);                                                                    \
+                if (nbits > 8)                                                                                         \
+                    *d += (max - *d) * *s / max;                                                                       \
+                else                                                                                                   \
+                    *d += FAST_DIV255((255 - *d) * *s);                                                                \
             }                                                                                                          \
             d += 1;                                                                                                    \
             s += 1;                                                                                                    \
         }                                                                                                              \
-        da += dst->linesize[3];                                                                                        \
-        sa += src->linesize[3];                                                                                        \
+        da += dst->linesize[3] / bytes;                                                                                \
+        sa += src->linesize[3] / bytes;                                                                                \
     }                                                                                                                  \
 }
 DEFINE_ALPHA_COMPOSITE(8, 8);