X-Git-Url: https://git.nihav.org/?p=nihav.git;a=blobdiff_plain;f=nihav-core%2Fsrc%2Fscale%2Fpalette%2Felbg.rs;h=9a7d96701e764e38729778da71daa7af6c6c61a2;hp=300b3f1610b5dc33f8a52c05df64099e2e671344;hb=b191eef3e3e1b6bea510c7e64606d8442f974f8b;hpb=b36f412c24813b14cb2b1f8fd151863e2a49c1e2 diff --git a/nihav-core/src/scale/palette/elbg.rs b/nihav-core/src/scale/palette/elbg.rs index 300b3f1..9a7d967 100644 --- a/nihav-core/src/scale/palette/elbg.rs +++ b/nihav-core/src/scale/palette/elbg.rs @@ -66,9 +66,6 @@ impl Cluster { } } fn calc_dist(&mut self) { - if self.count != 0 { - self.dist = (self.dist + self.count / 2) / self.count; - } } } @@ -198,7 +195,7 @@ impl ELBG { clu1.calc_dist(); clu0.dist + clu1.dist } - #[allow(clippy::cyclomatic_complexity)] + #[allow(clippy::cognitive_complexity)] pub fn quantise(&mut self, src: &[Pixel], dst: &mut [[u8; 3]; 256]) { if src.len() < 3 { return; @@ -232,14 +229,14 @@ impl ELBG { 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 < 10) && (dist < prev_dist - prev_dist / 100) { prev_dist = dist; for i in 0..256 { old_cb[i] = self.clusters[i].centroid; self.clusters[i].reset(); } // put pixels into the nearest clusters - indices.truncate(0); + indices.clear(); for entry in entries.iter() { let mut bestidx = 0; let mut bestdist = std::u32::MAX; @@ -270,8 +267,8 @@ impl ELBG { } let dmean = dist / 256; - low_u.truncate(0); - high_u.truncate(0); + low_u.clear(); + high_u.clear(); let mut used = [false; 256]; for (i, cluster) in self.clusters.iter().enumerate() { if cluster.dist < dmean {