summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2020-08-16 18:30:20 -0700
committeriximeow <me@iximeow.net>2020-08-16 18:30:20 -0700
commit6ba1324af6fcaf7e239605d04a93a616322d30df (patch)
tree8781a923eb9ddc1022ca836b2dc3b6409016c3ab
parent1f7084363e7c023e0710818f5b3364c797ef396f (diff)
very janky live view thing
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs51
-rw-r--r--src/qhyccd/mod.rs8
3 files changed, 51 insertions, 9 deletions
diff --git a/Cargo.toml b/Cargo.toml
index b4a22e0..df31255 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,3 +9,4 @@ build = "build.rs"
"png" = "0.13.2"
"crossbeam" = "0.7.2"
"crossbeam-channel" = "0.3.9"
+"show-image" = "0.6.4"
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();
diff --git a/src/qhyccd/mod.rs b/src/qhyccd/mod.rs
index 72a68b9..618d151 100644
--- a/src/qhyccd/mod.rs
+++ b/src/qhyccd/mod.rs
@@ -79,7 +79,7 @@ impl Settings {
Control::Gain => { self.gain = value as u32; }
Control::Offset => { self.offset = value as u32; }
Control::Exposure => { self.exposure = value as u64; }
- Control::TransferBit => { self.transfer_bit = value as u32; }
+ Control::TransferBit => { self.transfer_bit = value as u32; self.bpp = value as u8; }
Control::Channels => { self.channels = value as u8; }
Control::USBTraffic => { self.usb_traffic = value as u32; }
Control::RowNoiseRe => { self.row_noise_re = value as u32 == 1; }
@@ -381,7 +381,11 @@ impl Camera {
pub fn set_control(&mut self, control: Control, value: f64) -> Result<()> {
unsafe {
if self.has_control(control) {
- check(QHYCCDCam::SetQHYCCDParam(self.handle, control as i32, value))?;
+ if control == Control::TransferBit {
+ check(QHYCCDCam::SetQHYCCDBitsMode(self.handle, value as i32))?;
+ } else {
+ check(QHYCCDCam::SetQHYCCDParam(self.handle, control as i32, value))?;
+ }
self.settings.update_param(control, value);
Ok(())
} else {