codec_support/vq: use 1% improvement as a threshold in ELBG loop
[nihav.git] / nihav-codec-support / src / vq / generic_elbg.rs
index b2c838dc24236cfc15b30e13e4888ffd5b535ef9..91a56586d81bc1c619ddecde52d7edf6e8d6b3e0 100644 (file)
@@ -51,12 +51,11 @@ impl<T: VQElement, TS: VQElementSum<T>> Cluster<T, TS> {
         self.dist += u64::from(self.centroid.dist(entry.val)) * entry.count;
     }
     fn calc_centroid(&mut self) {
-        self.centroid = self.sum.get_centroid();
+        if self.count > 0 {
+            self.centroid = self.sum.get_centroid();
+        }
     }
     fn calc_dist(&mut self) {
-        if self.count != 0 {
-            self.dist = (self.dist + self.count / 2) / self.count;
-        }
     }
 }
 
@@ -182,7 +181,7 @@ impl<T: VQElement+Default, TS: VQElementSum<T>> ELBG<T, TS> {
         let mut rng = RNG::new();
         let mut iterations = 0usize;
         let mut do_elbg_step = true;
-        while (iterations < 20) && (dist < prev_dist - prev_dist / 1000) {
+        while (iterations < 20) && (dist < prev_dist - prev_dist / 100) {
             prev_dist = dist;
             for i in 0..dst.len() {
                 old_cb[i] = self.clusters[i].centroid;