From 5f2f2fd7859fcdfa80c27b6a15935fa8d03e92ff Mon Sep 17 00:00:00 2001 From: iximeow Date: Sun, 24 Mar 2019 16:39:33 -0700 Subject: swap red and blue from qhy camera, merge with endianness loop for perf (almost an additional second as separate steps) --- src/qhyccd/mod.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/qhyccd/mod.rs b/src/qhyccd/mod.rs index 654d743..0967b7e 100644 --- a/src/qhyccd/mod.rs +++ b/src/qhyccd/mod.rs @@ -257,11 +257,19 @@ impl Camera { bufsize as usize ) }; - 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; + for i in 0..(dataslice.len() / 6) { + let (b_low, b_high) = (dataslice[i * 6], dataslice[i * 6 + 1]); + let tmp2 = dataslice[i * 6 + 1]; + dataslice[i * 6 + 1] = dataslice[i * 6 + 4]; + dataslice[i * 6] = dataslice[i * 6 + 5]; + dataslice[i * 6 + 4] = b_high; + dataslice[i * 6 + 5] = b_low; + + let g_low = dataslice[i * 6 + 2]; + dataslice[i * 6 + 2] = dataslice[i * 6 + 3]; + dataslice[i * 6 + 3] = g_low; } + println!("the amount of data mod 6: {}", dataslice.len() % 6); let mut writer = encoder.write_header().unwrap(); writer.write_image_data(dataslice).unwrap(); dealloc(data as *mut u8, data_layout); -- cgit v1.1