try to do temperature change, wrongly

This commit is contained in:
Alon Levy 2023-12-29 08:24:14 +02:00
parent fe56b9f346
commit 57a2c3197e

View File

@ -20,10 +20,10 @@ fn get_packets_without_udp_header() -> anyhow::Result<(Vec<Vec<u8>>, usize, usiz
i += 1; i += 1;
size += offset; size += offset;
match packet { match packet {
PcapBlockOwned::Legacy(block) => { PcapBlockOwned::Legacy(_block) => {
println!("dunno"); println!("dunno");
} }
PcapBlockOwned::LegacyHeader(block) => { PcapBlockOwned::LegacyHeader(_block) => {
println!("dunnoheader"); println!("dunnoheader");
} }
PcapBlockOwned::NG(block) => { PcapBlockOwned::NG(block) => {
@ -89,6 +89,7 @@ impl Header {
}) })
} }
#[allow(dead_code)]
fn read_via_cast(data: &[u8]) -> anyhow::Result<&Self> { fn read_via_cast(data: &[u8]) -> anyhow::Result<&Self> {
let size = std::mem::size_of::<Self>(); let size = std::mem::size_of::<Self>();
if data.len() < size { if data.len() < size {
@ -110,7 +111,7 @@ fn main() -> anyhow::Result<()> {
let mut parts = vec![]; let mut parts = vec![];
for packet in data.iter() { for packet in data.iter() {
if let Ok(ref mut dump) = dump { if let Ok(ref mut dump) = dump {
dump.write_all(&packet); dump.write_all(&packet)?;
} }
let hdr = Header::read(packet)?; let hdr = Header::read(packet)?;
let data = packet[HDR_SIZE..].to_vec(); let data = packet[HDR_SIZE..].to_vec();
@ -121,6 +122,7 @@ fn main() -> anyhow::Result<()> {
parts.push(data); parts.push(data);
} }
println!("found {} frames", frames.len()); println!("found {} frames", frames.len());
println!("writing raw pngs");
let pb = ProgressBar::new(frames.len() as u64); let pb = ProgressBar::new(frames.len() as u64);
for (i, frame) in frames.iter().enumerate().progress_with(pb) { for (i, frame) in frames.iter().enumerate().progress_with(pb) {
let name = format!("{:03}.png", i); let name = format!("{:03}.png", i);
@ -131,7 +133,35 @@ fn main() -> anyhow::Result<()> {
encoder.set_color(png::ColorType::Grayscale); encoder.set_color(png::ColorType::Grayscale);
encoder.set_depth(png::BitDepth::Sixteen); encoder.set_depth(png::BitDepth::Sixteen);
let mut writer = encoder.write_header()?; let mut writer = encoder.write_header()?;
writer.write_image_data(&frame); writer.write_image_data(&frame)?;
}
println!("writing calibrated (value is temperature)");
let pb = ProgressBar::new(frames.len() as u64);
for (i, frame) in frames.iter().enumerate().progress_with(pb) {
let name = format!("temp_{:03}.png", i);
let path = Path::new(&name);
let file = File::create(path).unwrap();
let ref mut w = BufWriter::new(file);
let mut encoder = png::Encoder::new(w, 288, 384);
encoder.set_color(png::ColorType::Grayscale);
encoder.set_depth(png::BitDepth::Eight);
let mut writer = encoder.write_header()?;
let p = frame.as_ptr();
let samples: &[u16] = unsafe { std::slice::from_raw_parts(p.cast(), frame.len() / 2) };
let frame = samples
.iter()
.copied()
.map(|x| {
let x: f64 = x.into();
((-1.665884e-08) * x.powf(4.)
+ (1.347094e-05) * x.powf(3.)
+ (-4.396264e-03) * x.powf(2.)
+ (9.506939e-01) * x
+ (-6.353247e+01)) as u8
})
.collect::<Vec<u8>>();
writer.write_image_data(&frame)?;
} }
Ok(()) Ok(())