pub trait Camera: ConfigurableCamera {
Show 28 methods
// Required method
fn camera_as_raw(&self) -> u32_;
// Provided methods
fn view_size(&self) -> ViewSize { ... }
fn port_as_raw(&self) -> u32_ { ... }
fn is_busy(&self) -> Result<bool> { ... }
fn final_byte_length(&self) -> usize { ... }
fn final_view_size(&self) -> (i16, i16) { ... }
fn trimming(&self) -> Trimming { ... }
fn set_trimming(&mut self, trimming: Trimming) -> Result<()> { ... }
fn is_trimming(&self) -> bool { ... }
fn set_exposure(&mut self, exposure: i8) -> Result<()> { ... }
fn set_white_balance(&mut self, white_balance: WhiteBalance) -> Result<()> { ... }
fn set_sharpness(&mut self, sharpness: i8) -> Result<()> { ... }
fn set_auto_exposure(&mut self, enabled: bool) -> Result<()> { ... }
fn is_auto_exposure_enabled(&self) -> Result<bool> { ... }
fn flip_image(&mut self, flip: FlipMode) -> Result<()> { ... }
fn set_view_size(&mut self, size: ViewSize) -> Result<()> { ... }
fn set_frame_rate(&mut self, frame_rate: FrameRate) -> Result<()> { ... }
fn set_photo_mode(&mut self, photo_mode: PhotoMode) -> Result<()> { ... }
fn set_effect(&mut self, effect: Effect) -> Result<()> { ... }
fn set_contrast(&mut self, contrast: Contrast) -> Result<()> { ... }
fn set_lens_correction(
&mut self,
lens_correction: LensCorrection
) -> Result<()> { ... }
fn set_output_format(&mut self, format: OutputFormat) -> Result<()> { ... }
fn set_auto_exposure_window(
&mut self,
x: i16,
y: i16,
width: i16,
height: i16
) -> Result<()> { ... }
fn set_auto_white_balance_window(
&mut self,
x: i16,
y: i16,
width: i16,
height: i16
) -> Result<()> { ... }
fn set_noise_filter(&mut self, enabled: bool) -> Result<()> { ... }
fn set_image_quality_calibration(
&mut self,
data: ImageQualityCalibration
) -> Result<()> { ... }
fn image_quality_calibration(&self) -> Result<ImageQualityCalibration> { ... }
fn take_picture(
&mut self,
buffer: &mut [u8],
timeout: Duration
) -> Result<()> { ... }
}
Expand description
Generic functionality common to all cameras.
Required Methods§
sourcefn camera_as_raw(&self) -> u32_
fn camera_as_raw(&self) -> u32_
Returns the raw value of the selected camera.
Provided Methods§
sourcefn view_size(&self) -> ViewSize
fn view_size(&self) -> ViewSize
Returns view size of the selected camera.
§Notes
This view is the full resolution at which the camera will take the photo.
If you are interested in the final image’s size, calculated while taking into account all processing and modifications,
have a look at Camera::final_view_size()
.
sourcefn port_as_raw(&self) -> u32_
fn port_as_raw(&self) -> u32_
Returns the raw port of the selected camera.
sourcefn is_busy(&self) -> Result<bool>
fn is_busy(&self) -> Result<bool>
Returns true
if the camera is busy (receiving data).
§Example
use ctru::services::cam::{Cam, Camera};
let cam = Cam::new()?;
let inward = &cam.inner_cam;
// Inward cam is not busy since it is not being used.
assert!(!inward.is_busy()?);
sourcefn final_byte_length(&self) -> usize
fn final_byte_length(&self) -> usize
Returns the maximum amount of bytes the final image will occupy in memory based on the view size, trimming, pixel depth and other modifications set to the camera.
§Notes
The value returned will be double the image size if requested by BothOutwardCam
.
Remember to query this information again if any changes are applied to the Camera
configuration!
§Example
use ctru::services::cam::{Cam, Camera};
let cam = Cam::new()?;
let inward = &cam.inner_cam;
let transfer_count = inward.final_byte_length();
sourcefn final_view_size(&self) -> (i16, i16)
fn final_view_size(&self) -> (i16, i16)
Returns the dimensions of the final image based on the view size, trimming and other modifications set to the camera.
§Notes
Remember to query this information again if any changes are applied to the Camera
configuration!
§Example
use ctru::services::cam::{Cam, Camera, Trimming, ViewSize};
let mut cam = Cam::new()?;
let mut inward = &mut cam.inner_cam;
// We trim the image down so that it fits on a DS screen!
inward.set_trimming(Trimming::new_centered_with_view(ViewSize::DS));
// This result will take into account the trimming.
let final_resolution = inward.final_view_size();
sourcefn set_trimming(&mut self, trimming: Trimming) -> Result<()>
fn set_trimming(&mut self, trimming: Trimming) -> Result<()>
sourcefn is_trimming(&self) -> bool
fn is_trimming(&self) -> bool
Returns whether or not trimming is currently enabled for the camera.
sourcefn set_exposure(&mut self, exposure: i8) -> Result<()>
fn set_exposure(&mut self, exposure: i8) -> Result<()>
Set the exposure level of the camera.
sourcefn set_white_balance(&mut self, white_balance: WhiteBalance) -> Result<()>
fn set_white_balance(&mut self, white_balance: WhiteBalance) -> Result<()>
Set the white balance of the camera.
sourcefn set_sharpness(&mut self, sharpness: i8) -> Result<()>
fn set_sharpness(&mut self, sharpness: i8) -> Result<()>
Set the sharpness of the camera.
sourcefn set_auto_exposure(&mut self, enabled: bool) -> Result<()>
fn set_auto_exposure(&mut self, enabled: bool) -> Result<()>
Set whether auto exposure is enabled or disabled for the camera.
sourcefn is_auto_exposure_enabled(&self) -> Result<bool>
fn is_auto_exposure_enabled(&self) -> Result<bool>
Returns true
if auto exposure is enabled for the camera.
sourcefn flip_image(&mut self, flip: FlipMode) -> Result<()>
fn flip_image(&mut self, flip: FlipMode) -> Result<()>
Set the flip mode of the camera’s image.
sourcefn set_view_size(&mut self, size: ViewSize) -> Result<()>
fn set_view_size(&mut self, size: ViewSize) -> Result<()>
Set the view size of the camera.
§Notes
Calling this function will reset the trimming configuration.
sourcefn set_frame_rate(&mut self, frame_rate: FrameRate) -> Result<()>
fn set_frame_rate(&mut self, frame_rate: FrameRate) -> Result<()>
Set the frame rate of the camera.
sourcefn set_photo_mode(&mut self, photo_mode: PhotoMode) -> Result<()>
fn set_photo_mode(&mut self, photo_mode: PhotoMode) -> Result<()>
Set the photo mode of the camera.
sourcefn set_effect(&mut self, effect: Effect) -> Result<()>
fn set_effect(&mut self, effect: Effect) -> Result<()>
sourcefn set_contrast(&mut self, contrast: Contrast) -> Result<()>
fn set_contrast(&mut self, contrast: Contrast) -> Result<()>
Set the contrast of the camera.
sourcefn set_lens_correction(&mut self, lens_correction: LensCorrection) -> Result<()>
fn set_lens_correction(&mut self, lens_correction: LensCorrection) -> Result<()>
Set the lens correction of the camera.
sourcefn set_output_format(&mut self, format: OutputFormat) -> Result<()>
fn set_output_format(&mut self, format: OutputFormat) -> Result<()>
Set the output format of the camera.
sourcefn set_auto_exposure_window(
&mut self,
x: i16,
y: i16,
width: i16,
height: i16
) -> Result<()>
fn set_auto_exposure_window( &mut self, x: i16, y: i16, width: i16, height: i16 ) -> Result<()>
Set the region in which auto exposure should be based on.
§Arguments
x
- Starting x coordinate of the windowy
- Starting y coordinate of the windowwidth
- Width of the windowheight
- Height of the window
sourcefn set_auto_white_balance_window(
&mut self,
x: i16,
y: i16,
width: i16,
height: i16
) -> Result<()>
fn set_auto_white_balance_window( &mut self, x: i16, y: i16, width: i16, height: i16 ) -> Result<()>
Set the region in which auto white balance should be based on.
§Arguments
x
- Starting x coordinate of the windowy
- Starting y coordinate of the windowwidth
- Width of the windowheight
- Height of the window
§Notes
To activate automatic white balance, you must pass WhiteBalance::Auto
into Camera::set_white_balance()
.
sourcefn set_noise_filter(&mut self, enabled: bool) -> Result<()>
fn set_noise_filter(&mut self, enabled: bool) -> Result<()>
Set whether the noise filter should be enabled or disabled for the camera.
sourcefn set_image_quality_calibration(
&mut self,
data: ImageQualityCalibration
) -> Result<()>
fn set_image_quality_calibration( &mut self, data: ImageQualityCalibration ) -> Result<()>
Set the ImageQualityCalibration
for the camera.
sourcefn image_quality_calibration(&self) -> Result<ImageQualityCalibration>
fn image_quality_calibration(&self) -> Result<ImageQualityCalibration>
Returns the current ImageQualityCalibration
for the camera.
sourcefn take_picture(&mut self, buffer: &mut [u8], timeout: Duration) -> Result<()>
fn take_picture(&mut self, buffer: &mut [u8], timeout: Duration) -> Result<()>
Request the camera to take a picture and write it in a buffer.
§Errors
This function will return an error if the camera is already busy or if the timeout duration is reached.
§Notes
If the picture is taken using BothOutwardCam
, the buffer will have to be able to hold both images
(from each camera), which will be written into it sequentially.
Use Camera::final_byte_length()
to know how big the buffer needs to be to hold your next image.
§Example
use ctru::services::cam::{Cam, Camera, ViewSize, OutputFormat, WhiteBalance};
let mut cam = Cam::new()?;
// We borrow the inward facing `Camera`.
let camera = &mut cam.inner_cam;
camera.set_view_size(ViewSize::TopLCD)?;
camera.set_output_format(OutputFormat::Rgb565)?;
camera.set_noise_filter(true)?;
camera.set_auto_exposure(true)?;
camera.set_white_balance(WhiteBalance::Auto)?;
// Size of the top screen buffer at 2 bytes per pixel (RGB565).
let mut buffer = vec![0; camera.final_byte_length()];
// Take picture with 3 seconds of timeout.
camera.take_picture(&mut buffer, Duration::from_secs(3));