Made syncer code fuzzier to improve slanted images
This commit is contained in:
parent
e0e7db6a02
commit
ae3ee11468
|
@ -1,4 +1,4 @@
|
|||
[root]
|
||||
[[package]]
|
||||
name = "apt-decoder"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
|
|
|
@ -32,6 +32,7 @@ pub struct APTSyncer<'a> {
|
|||
pos : usize,
|
||||
nones_read: usize,
|
||||
max_level : f32,
|
||||
min_level: f32,
|
||||
iterator: Box<Iterator<Item=f32> + 'a>
|
||||
}
|
||||
|
||||
|
@ -39,11 +40,13 @@ impl<'a> APTSyncer<'a> {
|
|||
pub fn from<I>(mut iterator: I) -> APTSyncer<'a> where I: Iterator<Item=f32> + 'a {
|
||||
let mut state = [0.0; SYNC_LENGHT];
|
||||
let mut max_level = 0.0;
|
||||
let mut min_level = 1.0;
|
||||
for i in 0..SYNC_LENGHT {
|
||||
match iterator.next() {
|
||||
Some(x) => {
|
||||
state[i] = x;
|
||||
max_level = f32::max(x, max_level);
|
||||
max_level = 0.25 * x + max_level * 0.75;
|
||||
min_level = 0.25 * x + min_level * 0.75;
|
||||
},
|
||||
None => panic!("Could not retrieve enough samples to prime syncer")
|
||||
}
|
||||
|
@ -54,25 +57,33 @@ impl<'a> APTSyncer<'a> {
|
|||
pos: 0,
|
||||
nones_read: 0,
|
||||
max_level: max_level,
|
||||
min_level: min_level,
|
||||
iterator: Box::new(iterator)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_marker(&mut self) -> (bool, bool) {
|
||||
let mut is_a = true;
|
||||
let mut is_b = true;
|
||||
let mut count_a = 0;
|
||||
let mut count_b = 0;
|
||||
|
||||
for i in 0..SYNC_LENGHT {
|
||||
let sync_pos = (self.pos + i) % SYNC_LENGHT;
|
||||
let sample = self.state[sync_pos] / self.max_level;
|
||||
is_a = is_a && ((sample > 0.5 && SYNCA_SEQ[i]) || (sample <= 0.5 && !SYNCA_SEQ[i]));
|
||||
is_b = is_b && ((sample > 0.5 && SYNCB_SEQ[i]) || (sample <= 0.5 && !SYNCB_SEQ[i]));
|
||||
let sample = (self.state[sync_pos] - self.min_level) / (self.max_level - self.min_level);
|
||||
if (sample > 0.5 && SYNCA_SEQ[i]) || (sample <= 0.5 && !SYNCA_SEQ[i]) {
|
||||
count_a += 1;
|
||||
}
|
||||
if (sample > 0.5 && SYNCB_SEQ[i]) || (sample <= 0.5 && !SYNCB_SEQ[i]) {
|
||||
count_b += 1;
|
||||
}
|
||||
|
||||
if !is_a && !is_b {
|
||||
/*
|
||||
if !count_a && !count_b {
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
return (is_a, is_b);
|
||||
return (count_a > 35, count_b > 35);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +98,8 @@ impl<'a> Iterator for APTSyncer<'a> {
|
|||
match self.iterator.next() {
|
||||
Some(x) => {
|
||||
self.state[self.pos] = x;
|
||||
self.max_level = f32::max(x, self.max_level);
|
||||
self.max_level = 0.25 * x + self.max_level * 0.75;
|
||||
self.min_level = 0.25 * x + self.min_level * 0.75;
|
||||
},
|
||||
None => self.nones_read += 1
|
||||
};
|
||||
|
|
|
@ -85,6 +85,8 @@ fn main() {
|
|||
let mut progress = 0;
|
||||
let step = sample_count * 13 / 150 / 10;
|
||||
|
||||
let mut last_sync = 0;
|
||||
|
||||
print!("0%");
|
||||
std::io::stdout().flush().unwrap();
|
||||
for synced_sample in syncer {
|
||||
|
@ -95,14 +97,17 @@ fn main() {
|
|||
std::io::stdout().flush().unwrap();
|
||||
}
|
||||
|
||||
|
||||
let sample = match synced_sample {
|
||||
SyncedSample::Sample(s) => s,
|
||||
SyncedSample::SyncA(s) =>{
|
||||
println!(" [Sync A {}]", progress - last_sync);
|
||||
last_sync = progress;
|
||||
x = 0;
|
||||
s
|
||||
}
|
||||
SyncedSample::SyncB(s) =>{
|
||||
println!(" [Sync B {}]", progress - last_sync);
|
||||
last_sync = progress;
|
||||
x = PIXELS_PER_LINE / 2;
|
||||
s
|
||||
}
|
||||
|
@ -127,7 +132,7 @@ fn main() {
|
|||
Err(e) => panic!("Could not open outputfile: {}", e),
|
||||
Ok(f) => f
|
||||
};
|
||||
|
||||
|
||||
image::ImageLuma8(img).save(fout, image::PNG).unwrap();
|
||||
|
||||
println!("Done !");
|
||||
|
|
Loading…
Reference in New Issue