]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_delogo.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavfilter / vf_delogo.c
index f9c5ad76bedfa186c0aa38ba79b10c5d9db90fab..c52036228c07f26dc17257f285ad40bf1726a592 100644 (file)
@@ -2,20 +2,20 @@
  * Copyright (c) 2002 Jindrich Makovicka <makovick@gmail.com>
  * Copyright (c) 2011 Stefano Sabatini
  *
- * This file is part of Libav.
+ * This file is part of FFmpeg.
  *
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  *
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License along
- * with Libav; if not, write to the Free Software Foundation, Inc.,
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
@@ -89,18 +89,22 @@ static void apply_delogo(uint8_t *dst, int dst_linesize,
         for (x = logo_x1+1,
              xdst = dst+logo_x1+1,
              xsrc = src+logo_x1+1; x < logo_x2-1; x++, xdst++, xsrc++) {
-            interp = (topleft[src_linesize*(y-logo_y  -yclipt)]   +
-                      topleft[src_linesize*(y-logo_y-1-yclipt)]   +
-                      topleft[src_linesize*(y-logo_y+1-yclipt)])  * (logo_w-(x-logo_x))/logo_w
-                   + (topright[src_linesize*(y-logo_y-yclipt)]    +
-                      topright[src_linesize*(y-logo_y-1-yclipt)]  +
-                      topright[src_linesize*(y-logo_y+1-yclipt)]) * (x-logo_x)/logo_w
-                   + (topleft[x-logo_x-xclipl]                    +
-                      topleft[x-logo_x-1-xclipl]                  +
-                      topleft[x-logo_x+1-xclipl])                 * (logo_h-(y-logo_y))/logo_h
-                   + (botleft[x-logo_x-xclipl]                    +
-                      botleft[x-logo_x-1-xclipl]                  +
-                      botleft[x-logo_x+1-xclipl])                 * (y-logo_y)/logo_h;
+            interp =
+                (topleft[src_linesize*(y-logo_y  -yclipt)]   +
+                 topleft[src_linesize*(y-logo_y-1-yclipt)]   +
+                 topleft[src_linesize*(y-logo_y+1-yclipt)])  * (logo_w-(x-logo_x))/logo_w
+                +
+                (topright[src_linesize*(y-logo_y-yclipt)]    +
+                 topright[src_linesize*(y-logo_y-1-yclipt)]  +
+                 topright[src_linesize*(y-logo_y+1-yclipt)]) * (x-logo_x)/logo_w
+                +
+                (topleft[x-logo_x-xclipl]    +
+                 topleft[x-logo_x-1-xclipl]  +
+                 topleft[x-logo_x+1-xclipl]) * (logo_h-(y-logo_y))/logo_h
+                +
+                (botleft[x-logo_x-xclipl]    +
+                 botleft[x-logo_x-1-xclipl]  +
+                 botleft[x-logo_x+1-xclipl]) * (y-logo_y)/logo_h;
             interp /= 6;
 
             if (y >= logo_y+band && y < logo_y+logo_h-band &&
@@ -137,26 +141,17 @@ typedef struct {
 #define OFFSET(x) offsetof(DelogoContext, x)
 
 static const AVOption delogo_options[]= {
-    {"x",    "set logo x position",       OFFSET(x),    FF_OPT_TYPE_INT, {-1}, -1, INT_MAX },
-    {"y",    "set logo y position",       OFFSET(y),    FF_OPT_TYPE_INT, {-1}, -1, INT_MAX },
-    {"w",    "set logo width",            OFFSET(w),    FF_OPT_TYPE_INT, {-1}, -1, INT_MAX },
-    {"h",    "set logo height",           OFFSET(h),    FF_OPT_TYPE_INT, {-1}, -1, INT_MAX },
-    {"band", "set delogo area band size", OFFSET(band), FF_OPT_TYPE_INT, { 4}, -1, INT_MAX },
-    {"t",    "set delogo area band size", OFFSET(band), FF_OPT_TYPE_INT, { 4}, -1, INT_MAX },
-    {"show", "show delogo area",          OFFSET(show), FF_OPT_TYPE_INT, { 0},  0, 1       },
+    {"x",    "set logo x position",       OFFSET(x),    AV_OPT_TYPE_INT, {.dbl=-1}, -1, INT_MAX },
+    {"y",    "set logo y position",       OFFSET(y),    AV_OPT_TYPE_INT, {.dbl=-1}, -1, INT_MAX },
+    {"w",    "set logo width",            OFFSET(w),    AV_OPT_TYPE_INT, {.dbl=-1}, -1, INT_MAX },
+    {"h",    "set logo height",           OFFSET(h),    AV_OPT_TYPE_INT, {.dbl=-1}, -1, INT_MAX },
+    {"band", "set delogo area band size", OFFSET(band), AV_OPT_TYPE_INT, {.dbl= 4}, -1, INT_MAX },
+    {"t",    "set delogo area band size", OFFSET(band), AV_OPT_TYPE_INT, {.dbl= 4}, -1, INT_MAX },
+    {"show", "show delogo area",          OFFSET(show), AV_OPT_TYPE_INT, {.dbl= 0},  0, 1       },
     {NULL},
 };
 
-static const char *delogo_get_name(void *ctx)
-{
-    return "delogo";
-}
-
-static const AVClass delogo_class = {
-    .class_name = "DelogoContext",
-    .item_name  = delogo_get_name,
-    .option     = delogo_options,
-};
+AVFILTER_DEFINE_CLASS(delogo);
 
 static int query_formats(AVFilterContext *ctx)
 {
@@ -203,7 +198,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     if (delogo->show)
         delogo->band = 4;
 
-    av_log(ctx, AV_LOG_DEBUG, "x:%d y:%d, w:%d h:%d band:%d show:%d\n",
+    av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d show:%d\n",
            delogo->x, delogo->y, delogo->w, delogo->h, delogo->band, delogo->show);
 
     delogo->w += delogo->band*2;
@@ -214,27 +209,12 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     return 0;
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 {
-    AVFilterLink *outlink = inlink->dst->outputs[0];
-    AVFilterBufferRef *outpicref;
-
-    if (inpicref->perms & AV_PERM_PRESERVE) {
-        outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE,
-                                        outlink->w, outlink->h);
-        avfilter_copy_buffer_ref_props(outpicref, inpicref);
-        outpicref->video->w = outlink->w;
-        outpicref->video->h = outlink->h;
-    } else
-        outpicref = avfilter_ref_buffer(inpicref, ~0);
-
-    outlink->out_buf = outpicref;
-    ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
+    return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
-
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     DelogoContext *delogo = inlink->dst->priv;
     AVFilterLink *outlink = inlink->dst->outputs[0];
@@ -244,6 +224,7 @@ static void end_frame(AVFilterLink *inlink)
     int hsub0 = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
     int vsub0 = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
     int plane;
+    int ret;
 
     for (plane = 0; plane < 4 && inpicref->data[plane]; plane++) {
         int hsub = plane == 1 || plane == 2 ? hsub0 : 0;
@@ -258,9 +239,10 @@ static void end_frame(AVFilterLink *inlink)
                      delogo->show, direct);
     }
 
-    ff_draw_slice(outlink, 0, inlink->h, 1);
-    ff_end_frame(outlink);
-    avfilter_unref_buffer(outpicref);
+    if ((ret = ff_draw_slice(outlink, 0, inlink->h, 1)) < 0 ||
+        (ret = ff_end_frame(outlink)) < 0)
+        return ret;
+    return 0;
 }
 
 AVFilter avfilter_vf_delogo = {
@@ -270,16 +252,16 @@ AVFilter avfilter_vf_delogo = {
     .init          = init,
     .query_formats = query_formats,
 
-    .inputs    = (AVFilterPad[]) {{ .name             = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .start_frame      = start_frame,
-                                    .draw_slice       = null_draw_slice,
-                                    .end_frame        = end_frame,
-                                    .min_perms        = AV_PERM_WRITE | AV_PERM_READ,
-                                    .rej_perms        = AV_PERM_PRESERVE },
-                                  { .name = NULL}},
-    .outputs   = (AVFilterPad[]) {{ .name             = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .start_frame      = ff_inplace_start_frame,
+                                          .draw_slice       = null_draw_slice,
+                                          .end_frame        = end_frame,
+                                          .min_perms        = AV_PERM_WRITE | AV_PERM_READ,
+                                          .rej_perms        = AV_PERM_PRESERVE },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };