Browse code

lavfi/curves: add various const where it makes sense

Clément Bœsch authored on 2016/07/23 05:00:37
Showing 1 changed files
... ...
@@ -212,7 +212,7 @@ static int interpolate(AVFilterContext *ctx, uint8_t *y, const struct keypoint *
212 212
 
213 213
     double (*matrix)[3];
214 214
     double *h, *r;
215
-    int n = get_nb_points(points); // number of splines
215
+    const int n = get_nb_points(points); // number of splines
216 216
 
217 217
     if (n == 0) {
218 218
         for (i = 0; i < 256; i++)
... ...
@@ -247,9 +247,9 @@ static int interpolate(AVFilterContext *ctx, uint8_t *y, const struct keypoint *
247 247
     /* right-side of the polynomials, will be modified to contains the solution */
248 248
     point = points;
249 249
     for (i = 1; i < n - 1; i++) {
250
-        double yp = point->y,
251
-               yc = point->next->y,
252
-               yn = point->next->next->y;
250
+        const double yp = point->y;
251
+        const double yc = point->next->y;
252
+        const double yn = point->next->next->y;
253 253
         r[i] = 6 * ((yn-yc)/h[i] - (yc-yp)/h[i-1]);
254 254
         point = point->next;
255 255
     }
... ...
@@ -268,8 +268,8 @@ static int interpolate(AVFilterContext *ctx, uint8_t *y, const struct keypoint *
268 268
 
269 269
     /* tridiagonal solving of the linear system */
270 270
     for (i = 1; i < n; i++) {
271
-        double den = matrix[i][MD] - matrix[i][BD] * matrix[i-1][AD];
272
-        double k = den ? 1./den : 1.;
271
+        const double den = matrix[i][MD] - matrix[i][BD] * matrix[i-1][AD];
272
+        const double k = den ? 1./den : 1.;
273 273
         matrix[i][AD] *= k;
274 274
         r[i] = (r[i] - matrix[i][BD] * r[i - 1]) * k;
275 275
     }
... ...
@@ -286,24 +286,24 @@ static int interpolate(AVFilterContext *ctx, uint8_t *y, const struct keypoint *
286 286
     i = 0;
287 287
     av_assert0(point->next); // always at least 2 key points
288 288
     while (point->next) {
289
-        double yc = point->y;
290
-        double yn = point->next->y;
289
+        const double yc = point->y;
290
+        const double yn = point->next->y;
291 291
 
292
-        double a = yc;
293
-        double b = (yn-yc)/h[i] - h[i]*r[i]/2. - h[i]*(r[i+1]-r[i])/6.;
294
-        double c = r[i] / 2.;
295
-        double d = (r[i+1] - r[i]) / (6.*h[i]);
292
+        const double a = yc;
293
+        const double b = (yn-yc)/h[i] - h[i]*r[i]/2. - h[i]*(r[i+1]-r[i])/6.;
294
+        const double c = r[i] / 2.;
295
+        const double d = (r[i+1] - r[i]) / (6.*h[i]);
296 296
 
297 297
         int x;
298
-        int x_start = point->x       * 255;
299
-        int x_end   = point->next->x * 255;
298
+        const int x_start = point->x       * 255;
299
+        const int x_end   = point->next->x * 255;
300 300
 
301 301
         av_assert0(x_start >= 0 && x_start <= 255 &&
302 302
                    x_end   >= 0 && x_end   <= 255);
303 303
 
304 304
         for (x = x_start; x <= x_end; x++) {
305
-            double xx = (x - x_start) * 1/255.;
306
-            double yy = a + b*xx + c*xx*xx + d*xx*xx*xx;
305
+            const double xx = (x - x_start) * 1/255.;
306
+            const double yy = a + b*xx + c*xx*xx + d*xx*xx*xx;
307 307
             y[x] = av_clip_uint8(yy * 255);
308 308
             av_log(ctx, AV_LOG_DEBUG, "f(%f)=%f -> y[%d]=%d\n", xx, yy, x, y[x]);
309 309
         }
... ...
@@ -495,7 +495,7 @@ static av_cold int init(AVFilterContext *ctx)
495 495
 
496 496
     if (av_log_get_level() >= AV_LOG_VERBOSE) {
497 497
         for (i = 0; i < NB_COMP; i++) {
498
-            struct keypoint *point = comp_points[i];
498
+            const struct keypoint *point = comp_points[i];
499 499
             av_log(ctx, AV_LOG_VERBOSE, "#%d points:", i);
500 500
             while (point) {
501 501
                 av_log(ctx, AV_LOG_VERBOSE, " (%f;%f)", point->x, point->y);