pub struct ImageDescriptor {
pub channel_format: usize,
pub width: usize,
pub height: usize,
pub feature_channels: usize,
pub number_of_images: usize,
pub usage: usize,
pub storage_mode: usize,
}Expand description
Plain-Rust configuration for building a MPSImageDescriptor on the Swift side.
Fields§
§channel_format: usize§width: usize§height: usize§feature_channels: usize§number_of_images: usize§usage: usize§storage_mode: usizeImplementations§
Source§impl ImageDescriptor
impl ImageDescriptor
Sourcepub const fn new(
width: usize,
height: usize,
feature_channels: usize,
channel_format: usize,
) -> Self
pub const fn new( width: usize, height: usize, feature_channels: usize, channel_format: usize, ) -> Self
Create a single-image descriptor with sensible defaults for read/write image processing.
Examples found in repository?
examples/01_blur_image.rs (line 10)
4fn main() {
5 let device = MetalDevice::system_default().expect("no Metal device available");
6 let queue = device
7 .new_command_queue()
8 .expect("failed to create command queue");
9
10 let descriptor = ImageDescriptor::new(256, 256, 1, feature_channel_format::FLOAT32);
11 let src = Image::new(&device, descriptor).expect("failed to allocate source image");
12 let dst = Image::new(&device, descriptor).expect("failed to allocate destination image");
13
14 let mut impulse = vec![0.0_f32; 256 * 256];
15 let center_index = (256 / 2) * 256 + (256 / 2);
16 impulse[center_index] = 1.0;
17 src.write_f32(&impulse)
18 .expect("failed to upload source image");
19
20 let blur = ImageGaussianBlur::new(&device, 2.0).expect("failed to create gaussian blur");
21 let command_buffer = queue
22 .new_command_buffer()
23 .expect("failed to allocate command buffer");
24 blur.encode_image(&command_buffer, &src, &dst);
25 command_buffer.commit();
26 command_buffer.wait_until_completed();
27
28 let output = dst.read_f32().expect("failed to download blurred image");
29 let center_value = output[center_index];
30 let neighbor_value = output[center_index + 1];
31 let corner_value = output[0];
32 let total_energy: f32 = output.iter().sum();
33
34 assert!(
35 center_value < 1.0,
36 "center should have blurred away from impulse"
37 );
38 assert!(
39 neighbor_value > 0.0,
40 "neighbor should receive energy after blur"
41 );
42 assert!(
43 center_value > neighbor_value,
44 "center should remain strongest sample"
45 );
46 assert!(corner_value.abs() < 1.0e-6, "corners should stay at zero");
47 assert!(
48 (total_energy - 1.0).abs() < 1.0e-2,
49 "gaussian blur should preserve energy, got {total_energy}"
50 );
51
52 println!(
53 "blur smoke passed: center={center_value:.6} neighbor={neighbor_value:.6} sum={total_energy:.6}"
54 );
55}Trait Implementations§
Source§impl Clone for ImageDescriptor
impl Clone for ImageDescriptor
Source§fn clone(&self) -> ImageDescriptor
fn clone(&self) -> ImageDescriptor
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ImageDescriptor
impl Debug for ImageDescriptor
impl Copy for ImageDescriptor
Auto Trait Implementations§
impl Freeze for ImageDescriptor
impl RefUnwindSafe for ImageDescriptor
impl Send for ImageDescriptor
impl Sync for ImageDescriptor
impl Unpin for ImageDescriptor
impl UnsafeUnpin for ImageDescriptor
impl UnwindSafe for ImageDescriptor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more