]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_lut.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavfilter / vf_lut.c
index 2824f03b09df4d8636280d2c33437d91f14011f8..4c0cdfc29ca8f65dda506fd5b527a55b07ba52c0 100644 (file)
@@ -260,14 +260,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     AVFilterLink *outlink = ctx->outputs[0];
     AVFrame *out;
     uint8_t *inrow, *outrow, *inrow0, *outrow0;
-    int i, j, plane;
+    int i, j, plane, direct = 0;
 
-    out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
-    if (!out) {
-        av_frame_free(&in);
-        return AVERROR(ENOMEM);
+    if (av_frame_is_writable(in)) {
+        direct = 1;
+        out = in;
+    } else {
+        out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+        if (!out) {
+            av_frame_free(&in);
+            return AVERROR(ENOMEM);
+        }
+        av_frame_copy_props(out, in);
     }
-    av_frame_copy_props(out, in);
 
     if (lut->is_rgb) {
         /* packed */
@@ -280,15 +285,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
             inrow  = inrow0;
             outrow = outrow0;
             for (j = 0; j < w; j++) {
-                outrow[0] = tab[0][inrow[0]];
-                if (lut->step>1) {
-                    outrow[1] = tab[1][inrow[1]];
-                    if (lut->step>2) {
-                        outrow[2] = tab[2][inrow[2]];
-                        if (lut->step>3) {
-                            outrow[3] = tab[3][inrow[3]];
-                        }
-                    }
+                switch (lut->step) {
+                case 4:  outrow[3] = tab[3][inrow[3]]; // Fall-through
+                case 3:  outrow[2] = tab[2][inrow[2]]; // Fall-through
+                case 2:  outrow[1] = tab[1][inrow[1]]; // Fall-through
+                default: outrow[0] = tab[0][inrow[0]];
                 }
                 outrow += lut->step;
                 inrow  += lut->step;
@@ -316,7 +317,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         }
     }
 
-    av_frame_free(&in);
+    if (!direct)
+        av_frame_free(&in);
+
     return ff_filter_frame(outlink, out);
 }
 
@@ -354,7 +357,7 @@ static const AVFilterPad outputs[] = {
 #define lut_options options
 AVFILTER_DEFINE_CLASS(lut);
 
-static int lut_init(AVFilterContext *ctx, const char *args)
+static int lut_init(AVFilterContext *ctx)
 {
     return 0;
 }
@@ -367,7 +370,7 @@ DEFINE_LUT_FILTER(lut, "Compute and apply a lookup table to the RGB/YUV input vi
 #define lutyuv_options options
 AVFILTER_DEFINE_CLASS(lutyuv);
 
-static int lutyuv_init(AVFilterContext *ctx, const char *args)
+static int lutyuv_init(AVFilterContext *ctx)
 {
     LutContext *lut = ctx->priv;
 
@@ -384,7 +387,7 @@ DEFINE_LUT_FILTER(lutyuv, "Compute and apply a lookup table to the YUV input vid
 #define lutrgb_options options
 AVFILTER_DEFINE_CLASS(lutrgb);
 
-static int lutrgb_init(AVFilterContext *ctx, const char *args)
+static int lutrgb_init(AVFilterContext *ctx)
 {
     LutContext *lut = ctx->priv;
 
@@ -405,7 +408,7 @@ static const AVOption negate_options[] = {
 
 AVFILTER_DEFINE_CLASS(negate);
 
-static int negate_init(AVFilterContext *ctx, const char *args)
+static int negate_init(AVFilterContext *ctx)
 {
     LutContext *lut = ctx->priv;
     int i;
@@ -421,7 +424,7 @@ static int negate_init(AVFilterContext *ctx, const char *args)
         }
     }
 
-    return lut_init(ctx, NULL);
+    return 0;
 }
 
 DEFINE_LUT_FILTER(negate, "Negate input video.");