changeset 2064:b77fe059dd09 libavcodec

fix normalization
author michael
date Sun, 06 Jun 2004 20:15:53 +0000
parents 99556d33f102
children 9e4bebc39ade
files imgresample.c
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/imgresample.c	Sun Jun 06 19:44:05 2004 +0000
+++ b/imgresample.c	Sun Jun 06 20:15:53 2004 +0000
@@ -545,7 +545,7 @@
 static void build_filter(int16_t *filter, float factor)
 {
     int ph, i, v;
-    float x, y, tab[NB_TAPS], norm, mult;
+    float x, y, tab[NB_TAPS], norm, mult, target;
 
     /* if upsampling, only need to interpolate, no filter */
     if (factor > 1.0)
@@ -571,10 +571,13 @@
         }
 
         /* normalize so that an uniform color remains the same */
-        mult = (float)(1 << FILTER_BITS) / norm;
+        target= 1 << FILTER_BITS;
         for(i=0;i<NB_TAPS;i++) {
-            v = (int)(tab[i] * mult);
+            mult = target / norm;
+            v = lrintf(tab[i] * mult);
             filter[ph * NB_TAPS + i] = v;
+            norm -= tab[i];
+            target -= v;
         }
     }
 }