diff options
Diffstat (limited to 'src/qhyccd/mod.rs')
-rw-r--r-- | src/qhyccd/mod.rs | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/qhyccd/mod.rs b/src/qhyccd/mod.rs index 192b943..4404ddb 100644 --- a/src/qhyccd/mod.rs +++ b/src/qhyccd/mod.rs @@ -104,6 +104,26 @@ impl Camera { } } } + pub fn get_param_limits(&self, control: Control) -> Result<(f64, f64, f64)> { + unsafe { + if self.has_param(control) { + let mut min = 0f64; + let mut max = 0f64; + let mut step = 0f64; + match check(QHYCCDCam::GetQHYCCDParamMinMaxStep(self.handle, control as i32, &mut min, &mut max, &mut step)) { + Ok(_) => { + Ok((min, max, step)) + }, + Err(_) => { + Err(CameraError::QHYError) + } + } + } else { + Err(CameraError::InvalidControl) + } + } + } + pub fn get_param(&self, control: Control) -> f64 { unsafe { QHYCCDCam::GetQHYCCDParam(self.handle, control as i32) @@ -227,15 +247,22 @@ impl Camera { let ref mut w = BufWriter::new(file); let mut encoder = png::Encoder::new(w, castediw as u32, castedih as u32); encoder.set(png::ColorType::RGB).set(png::BitDepth::Sixteen); - let mut writer = encoder.write_header().unwrap(); - writer.write_image_data( + // crazy theory, endianness might be wrong... + // so flip the bytes first + let mut dataslice: &mut [u8] = unsafe { - std::slice::from_raw_parts( + std::slice::from_raw_parts_mut( data, bufsize as usize ) - } - ).unwrap(); + }; + for i in 0..(bufsize as usize / 2) { + let tmp = dataslice[i * 2]; + dataslice[i * 2] = dataslice[i * 2 + 1]; + dataslice[i * 2 + 1] = tmp; + } + let mut writer = encoder.write_header().unwrap(); + writer.write_image_data(dataslice).unwrap(); dealloc(data as *mut u8, data_layout); Ok(()) } |