OSDN Git Service

avfilter/vf_premultiply: add planes option
authorPaul B Mahol <onemda@gmail.com>
Sun, 23 Apr 2017 16:19:40 +0000 (18:19 +0200)
committerPaul B Mahol <onemda@gmail.com>
Sun, 23 Apr 2017 16:21:51 +0000 (18:21 +0200)
Signed-off-by: Paul B Mahol <onemda@gmail.com>
doc/filters.texi
libavfilter/vf_premultiply.c

index ac32995..4c733f0 100644 (file)
@@ -11077,6 +11077,14 @@ of second stream as alpha.
 
 Both streams must have same dimensions and same pixel format.
 
+The filter accepts the following option:
+
+@table @option
+@item planes
+Set which planes will be processed, unprocessed planes will be copied.
+By default value 0xf, all planes will be processed.
+@end table
+
 @section prewitt
 Apply prewitt operator to input video stream.
 
index e1b79ab..8a5f9ea 100644 (file)
@@ -30,6 +30,7 @@
 typedef struct PreMultiplyContext {
     const AVClass *class;
     int width[4], height[4];
+    int linesize[4];
     int nb_planes;
     int planes;
     int half, depth, offset;
@@ -47,6 +48,7 @@ typedef struct PreMultiplyContext {
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
 static const AVOption premultiply_options[] = {
+    { "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, FLAGS },
     { NULL }
 };
 
@@ -269,6 +271,12 @@ static int process_frame(FFFrameSync *fs)
         }
 
         for (p = 0; p < s->nb_planes; p++) {
+            if (!((1 << p) & s->planes)) {
+                av_image_copy_plane(out->data[p], out->linesize[p], base->data[p], base->linesize[p],
+                                    s->linesize[p], s->height[p]);
+                continue;
+            }
+
             s->premultiply[p](base->data[p], alpha->data[0],
                               out->data[p],
                               base->linesize[p], alpha->linesize[0],
@@ -287,10 +295,13 @@ static int config_input(AVFilterLink *inlink)
     AVFilterContext *ctx = inlink->dst;
     PreMultiplyContext *s = ctx->priv;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
-    int vsub, hsub;
+    int vsub, hsub, ret;
 
     s->nb_planes = av_pix_fmt_count_planes(inlink->format);
 
+    if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
+        return ret;
+
     hsub = desc->log2_chroma_w;
     vsub = desc->log2_chroma_h;
     s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, vsub);