diff --git a/ctru-rs/examples/camera-image.rs b/ctru-rs/examples/camera-image.rs index 6954442..4302325 100644 --- a/ctru-rs/examples/camera-image.rs +++ b/ctru-rs/examples/camera-image.rs @@ -9,7 +9,7 @@ const WIDTH: usize = 400; const HEIGHT: usize = 240; // The screen size is the width and height multiplied by 2 (RGB565 store pixels in 2 bytes) -const BUF_SIZE: usize = WIDTH * HEIGHT * 2; +// const BUF_SIZE: usize = WIDTH * HEIGHT * 2; const WAIT_TIMEOUT: Duration = Duration::from_micros(300); @@ -55,9 +55,8 @@ fn main() { .set_trimming(false) .expect("Failed to disable trimming"); } - let mut buf = vec![128u8; BUF_SIZE / 2]; - let mut lol = vec![255u8; BUF_SIZE / 2]; - buf.append(&mut lol); + + let mut buf; println!("\nPress R to take a new picture"); println!("Press Start to exit to Homebrew Launcher"); @@ -72,8 +71,6 @@ fn main() { if keys_down.contains(KeyPad::KEY_R) { println!("Capturing new image"); - cam.play_shutter_sound(CamShutterSoundType::NORMAL) - .expect("Failed to play shutter sound"); let camera = &mut cam.outer_right_cam; @@ -84,21 +81,24 @@ fn main() { WAIT_TIMEOUT, ) .expect("Failed to take picture"); - } - let img = rotate_image(&buf, WIDTH, HEIGHT); + cam.play_shutter_sound(CamShutterSoundType::NORMAL) + .expect("Failed to play shutter sound"); - unsafe { - gfx.top_screen - .borrow_mut() - .get_raw_framebuffer() - .ptr - .copy_from(img.as_ptr(), img.len()); - } + let img = rotate_image(&buf, WIDTH, HEIGHT); - gfx.flush_buffers(); - gfx.swap_buffers(); - gfx.wait_for_vblank(); + unsafe { + gfx.top_screen + .borrow_mut() + .get_raw_framebuffer() + .ptr + .copy_from(img.as_ptr(), img.len()); + } + + gfx.flush_buffers(); + gfx.swap_buffers(); + gfx.wait_for_vblank(); + } } } diff --git a/ctru-rs/src/services/cam.rs b/ctru-rs/src/services/cam.rs index 4339340..528a27f 100644 --- a/ctru-rs/src/services/cam.rs +++ b/ctru-rs/src/services/cam.rs @@ -731,7 +731,7 @@ pub trait Camera { Ok::(buf_size) }?; - let screen_size = u32::from(width) * u32::from(width) * 2; + let screen_size = u32::from(width) * u32::from(height) * 2; let mut buf = vec![0u8; usize::try_from(screen_size).unwrap()];