diff options
author | iximeow <me@iximeow.net> | 2020-08-16 18:30:20 -0700 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2020-08-16 18:30:20 -0700 |
commit | 6ba1324af6fcaf7e239605d04a93a616322d30df (patch) | |
tree | 8781a923eb9ddc1022ca836b2dc3b6409016c3ab /src/main.rs | |
parent | 1f7084363e7c023e0710818f5b3364c797ef396f (diff) |
very janky live view thing
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index ce1c19e..7edf300 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,20 +72,57 @@ fn main() { let (frame_sender, free_frames) = unbounded(); std::thread::spawn(move || { + use show_image::make_window; + let window = make_window("image").expect("can make the window"); + loop { select! { recv(image_reader) -> msg => { match msg { Ok(ImageInfo { mut data, dimensions, target, image_id, properties }) => { - match dimensions.channels { - 1 => { - qhyccd::fix_endianness(data.as_mut_slice()); - }, - 3 => { - qhyccd::fix_channels_and_endianness(data.as_mut_slice()); + if dimensions.bpp == 16 { + match dimensions.channels { + 1 => { + qhyccd::fix_endianness(data.as_mut_slice()); + }, + 3 => { + qhyccd::fix_channels_and_endianness(data.as_mut_slice()); + } + c => { panic!("unsupported channel count: {}", c); } + } + } + // downscales a mono image by `factor` + fn downscale(data: &[u8], width: u32, height: u32, factor: u8) -> Vec<u8> { + let factor = factor as u32; + assert!(width % factor == 0); + assert!(height % factor == 0); + let mut result = vec![0; ((width / factor) * (height / factor)) as usize]; + for h in 0..(height / factor) { + for w in 0..(width / factor) { + let mut acc = 0u32; + let srcrow = h * width * factor; + let srcpx = srcrow + w * factor; + let dstrow = h * (width / factor); + for i in 0..factor { + for j in 0..factor { + acc = acc.saturating_add(data[(srcpx + i as u32 * width + j as u32) as usize] as u32); + } + } + result[(dstrow + w) as usize] = (acc / 4) as u8; + } } - c => { panic!("unsupported channel count: {}", c); } + return result; } + let scale_factor = 2; + if scale_factor != 1 { + let downscaled = downscale(data.as_slice(), dimensions.width, dimensions.height, scale_factor); + let image_info = show_image::ImageInfo::mono8(dimensions.width as usize / scale_factor as usize, dimensions.height as usize / scale_factor as usize); + window.set_image(&(downscaled.as_slice(), image_info), "image-001"); + } else { + let image_info = show_image::ImageInfo::mono8(dimensions.width as usize, dimensions.height as usize); + window.set_image(&(data.as_slice(), image_info), "image-001"); + } + record_image(data.as_slice(), dimensions, target, image_id, &properties); println!("pretend i wrote image {}_{}", target, image_id); frame_sender.send(data).unwrap(); |