]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_colorconstancy.c
avfilter: Constify all AVFilters
[ffmpeg] / libavfilter / vf_colorconstancy.c
index e8271f34ec70a3c88388ef573b55d5d660e12924..e44d9afa0197c7d47645ab5a26570942760761b4 100644 (file)
@@ -28,7 +28,6 @@
  * J. van de Weijer, Th. Gevers, A. Gijsenij "Edge-Based Color Constancy".
  */
 
-#include "libavutil/bprint.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
@@ -42,6 +41,8 @@
 
 #define GREY_EDGE "greyedge"
 
+#define SQRT3 1.73205080757
+
 #define NUM_PLANES    3
 #define MAX_DIFF_ORD  2
 #define MAX_META_DATA 4
@@ -120,7 +121,6 @@ static int set_gauss(AVFilterContext *ctx)
             for (; i >= 0; --i) {
                 av_freep(&s->gauss[i]);
             }
-            av_log(ctx, AV_LOG_ERROR, "Out of memory while allocating gauss buffers.\n");
             return AVERROR(ENOMEM);
         }
     }
@@ -145,7 +145,7 @@ static int set_gauss(AVFilterContext *ctx)
         sum1 = 0.0;
         for (i = 0; i < filtersize; ++i) {
             s->gauss[1][i] = - (GINDX(filtersize, i) / pow(sigma, 2)) * s->gauss[0][i];
-            sum1 += s->gauss[1][i] *GINDX(filtersize, i);
+            sum1 += s->gauss[1][i] * GINDX(filtersize, i);
         }
 
         for (i = 0; i < filtersize; ++i) {
@@ -222,7 +222,6 @@ static int setup_derivative_buffers(AVFilterContext* ctx, ThreadData *td)
             td->data[b][p] = av_mallocz_array(s->planeheight[p] * s->planewidth[p], sizeof(*td->data[b][p]));
             if (!td->data[b][p]) {
                 cleanup_derivative_buffers(td, b + 1, p);
-                av_log(ctx, AV_LOG_ERROR, "Out of memory while allocating derivatives buffers.\n");
                 return AVERROR(ENOMEM);
             }
         }
@@ -279,7 +278,7 @@ static int slice_get_derivative(AVFilterContext* ctx, void* arg, int jobnr, int
                     dst[INDX2D(r, c, width)] = 0;
                     for (g = 0; g < filtersize; ++g) {
                         dst[INDX2D(r, c, width)] += GAUSS(src, r,                        c + GINDX(filtersize, g),
-                                                          in_linesize, height, width, gauss[GINDX(filtersize, g)]);
+                                                          in_linesize, height, width, gauss[g]);
                     }
                 }
             }
@@ -294,7 +293,7 @@ static int slice_get_derivative(AVFilterContext* ctx, void* arg, int jobnr, int
                     dst[INDX2D(r, c, width)] = 0;
                     for (g = 0; g < filtersize; ++g) {
                         dst[INDX2D(r, c, width)] += GAUSS(src, r + GINDX(filtersize, g), c,
-                                                          width, height, width, gauss[GINDX(filtersize, g)]);
+                                                          width, height, width, gauss[g]);
                     }
                 }
             }
@@ -595,7 +594,6 @@ static int diagonal_transformation(AVFilterContext *ctx, void *arg, int jobnr, i
     ThreadData *td = arg;
     AVFrame *in = td->in;
     AVFrame *out = td->out;
-    double sqrt3 = pow(3.0, 0.5);
     int plane;
 
     for (plane = 0; plane < NUM_PLANES; ++plane) {
@@ -610,7 +608,7 @@ static int diagonal_transformation(AVFilterContext *ctx, void *arg, int jobnr, i
         unsigned i;
 
         for (i = slice_start; i < slice_end; ++i) {
-            temp = src[i] / (s->white[plane] * sqrt3);
+            temp = src[i] / (s->white[plane] * SQRT3);
             dst[i] = av_clip_uint8((int)(temp + 0.5));
         }
     }
@@ -657,12 +655,12 @@ static int config_props(AVFilterLink *inlink)
     double sigma = s->sigma;
     int ret;
 
-    if (!sigma && s->difford) {
-        av_log(ctx, AV_LOG_ERROR, "Sigma can't be set to 0 when difford > 0.\n");
+    if (!floor(break_off_sigma * sigma + 0.5) && s->difford) {
+        av_log(ctx, AV_LOG_ERROR, "floor(%f * sigma) must be > 0 when difford > 0.\n", break_off_sigma);
         return AVERROR(EINVAL);
     }
 
-    s->filtersize = 2 * floor(break_off_sigma * s->sigma + 0.5) + 1;
+    s->filtersize = 2 * floor(break_off_sigma * sigma + 0.5) + 1;
     if (ret=set_gauss(ctx)) {
         return ret;
     }
@@ -682,24 +680,30 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     AVFilterLink *outlink = ctx->outputs[0];
     AVFrame *out;
     int ret;
+    int direct = 0;
 
     ret = illumination_estimation(ctx, in);
     if (ret) {
+        av_frame_free(&in);
         return ret;
     }
 
     if (av_frame_is_writable(in)) {
+        direct = 1;
         out = in;
     } else {
         out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
         if (!out) {
-            av_log(ctx, AV_LOG_ERROR, "Out of memory while allocating output video buffer.\n");
+            av_frame_free(&in);
             return AVERROR(ENOMEM);
         }
         av_frame_copy_props(out, in);
     }
     chromatic_adaptation(ctx, in, out);
 
+    if (!direct)
+        av_frame_free(&in);
+
     return ff_filter_frame(outlink, out);
 }
 
@@ -743,7 +747,7 @@ static const AVOption greyedge_options[] = {
 
 AVFILTER_DEFINE_CLASS(greyedge);
 
-AVFilter ff_vf_greyedge = {
+const AVFilter ff_vf_greyedge = {
     .name          = GREY_EDGE,
     .description   = NULL_IF_CONFIG_SMALL("Estimates scene illumination by grey edge assumption."),
     .priv_size     = sizeof(ColorConstancyContext),