### Box from Method Example Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Demonstrates the usage of the `Box::from` method to convert a value into a heap-allocated Box. This example shows creating a boxed integer. ```rust let x = 5; let boxed = Box::new(5); assert_eq!(Box::from(x), boxed); ``` -------------------------------- ### Handling File Metadata Operations with and_then Source: https://docs.rs/image/latest/image/error/type.ImageResult.html Shows how to use `and_then` to chain fallible operations like getting file metadata and its modification time. This example highlights handling potential errors like file not found. ```Rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### Get Sample Layout Source: https://docs.rs/image/latest/image/type.GrayAlphaImage.html Retrieves the sample layout of the buffer when viewed as a matrix of samples. ```rust pub fn sample_layout(&self) -> SampleLayout ``` -------------------------------- ### sample_layout Source: https://docs.rs/image/latest/image/type.RgbaImage.html Gets the format of the buffer when viewed as a matrix of samples. ```APIDOC ## sample_layout Get the format of the buffer when viewed as a matrix of samples. ### Method ```rust pub fn sample_layout(&self) -> SampleLayout ``` #### Returns - `SampleLayout`: The sample layout of the buffer. ``` -------------------------------- ### Rust as_simd Example with Short Slice Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Illustrates the `as_simd` method with a short slice, showing how it handles cases where there are not enough elements for the middle SIMD slice. It also demonstrates chaining prefix and suffix iterators. ```rust #![feature(portable_simd)] use core::simd::prelude::*; let short = &[1, 2, 3]; let (prefix, middle, suffix) = short.as_simd::<4>(); assert_eq!(middle, []); // Not enough elements for anything in the middle // They might be split in any possible way between prefix and suffix let it = prefix.iter().chain(suffix).copied(); assert_eq!(it.collect::>(), vec![1, 2, 3]); ``` -------------------------------- ### Mutable reverse chunk splitting with remainder Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Use `as_rchunks_mut` to get mutable access to chunks of `N` elements and a mutable remainder slice, starting from the end. This allows for in-place modification from the end of the slice. ```rust let v = &mut [0, 0, 0, 0, 0]; let mut count = 1; let (remainder, chunks) = v.as_rchunks_mut(); remainder[0] = 9; for chunk in chunks { *chunk = [count; 2]; count += 1; } assert_eq!(v, &[9, 1, 1, 2, 2]); ``` -------------------------------- ### Init Source: https://docs.rs/image/latest/image/buffer/struct.RowsMut.html The type for initializers. ```APIDOC ## type Init = T ### Description The type for initializers. ### Type Alias - `T`: The type of the initializer. ``` -------------------------------- ### Pointable::Init Source: https://docs.rs/image/latest/image/buffer/struct.Pixels.html The type for initializers. ```APIDOC #### type Init = T ### Description The type for initializers. ``` -------------------------------- ### Get a reference to the underlying image Source: https://docs.rs/image/latest/image/struct.SubImage.html Gets a reference to the underlying image. ```rust pub fn inner(&self) -> &I::Target ``` -------------------------------- ### Get Type ID Source: https://docs.rs/image/latest/image/codecs/avif/struct.AvifDecoder.html Gets the `TypeId` of `self`. This is a blanket implementation for the `Any` trait. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Pointable::init Source: https://docs.rs/image/latest/image/buffer/struct.Pixels.html Initializes a with the given initializer. ```APIDOC #### unsafe fn init(init: ::Init) -> usize ### Description Initializes a with the given initializer. ### Parameters - **init**: ::Init - The initializer value. ### Returns - usize - The pointer to the initialized memory. ``` -------------------------------- ### new Source: https://docs.rs/image/latest/image/type.GrayImage.html Creates a new image buffer with the specified width and height, initialized with zero values. The color space is initially set to sRGB. ```APIDOC ## pub fn new(width: u32, height: u32) -> ImageBuffer> ### Description Creates a new image buffer based on a `Vec`. All pixels are initialized to zero. ### Panics Panics when the resulting image is larger than the maximum size of a vector. ### Source [Source Link] ``` -------------------------------- ### Get a mutable reference to the underlying image Source: https://docs.rs/image/latest/image/struct.SubImage.html Gets a mutable reference to the underlying image. ```rust pub fn inner_mut(&mut self) -> &mut I::Target ``` -------------------------------- ### As Flat Samples View Source: https://docs.rs/image/latest/image/type.GrayAlphaImage.html Returns a view on the raw sample buffer. See into_flat_samples for more details on the buffer layout. ```rust pub fn as_flat_samples(&self) -> FlatSamples<&[P::Subpixel]> ``` -------------------------------- ### Get Pixel by Coordinates Source: https://docs.rs/image/latest/image/type.GrayAlphaImage.html Gets a reference to the pixel at the specified (x, y) coordinates. Panics if the coordinates are out of bounds. ```rust pub fn get_pixel(&self, x: u32, y: u32) -> &P ``` -------------------------------- ### Cicp Initialization Source: https://docs.rs/image/latest/image/metadata/struct.Cicp.html Provides methods for initializing and managing objects via pointers. ```APIDOC ## unsafe fn init(init: ::Init) -> usize ### Description Initializes a with the given initializer. ### Parameters * **init** (::Init) - Description: The initializer for the object. ### Returns * usize - The pointer to the initialized object. ``` ```APIDOC ## unsafe fn deref<'a>(ptr: usize) -> &'a T ### Description Dereferences the given pointer to provide immutable access to the object. ### Parameters * **ptr** (usize) - Description: The pointer to the object. ### Returns * &'a T - An immutable reference to the object. ``` ```APIDOC ## unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T ### Description Mutably dereferences the given pointer to provide mutable access to the object. ### Parameters * **ptr** (usize) - Description: The pointer to the object. ### Returns * &'a mut T - A mutable reference to the object. ``` ```APIDOC ## unsafe fn drop(ptr: usize) ### Description Drops the object pointed to by the given pointer, releasing its resources. ### Parameters * **ptr** (usize) - Description: The pointer to the object to be dropped. ``` -------------------------------- ### Get Pixel by Coordinates Safely Source: https://docs.rs/image/latest/image/type.GrayAlphaImage.html Gets a reference to the pixel at the specified (x, y) coordinates, returning None if the index is out of bounds. ```rust pub fn get_pixel_checked(&self, x: u32, y: u32) -> Option<&P> ``` -------------------------------- ### Get a subsection of an iterator Source: https://docs.rs/image/latest/image/buffer/struct.EnumeratePixels.html Use `get` to obtain an iterator over a specific subsection of the original iterator, defined by an index type that implements `IteratorIndex`. ```rust fn get(self, index: R) -> >::Output where Self: Sized, R: IteratorIndex, ``` -------------------------------- ### Create a new PngEncoder Source: https://docs.rs/image/latest/image/codecs/png/struct.PngEncoder.html Instantiate a PngEncoder with a writer. This is the basic way to start encoding PNG images. ```rust pub fn new(w: W) -> PngEncoder ``` -------------------------------- ### Get Element or Subslice by Index Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Safely gets a reference to an element or subslice using various index types. Returns None if the index is out of bounds. ```rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### QoiDecoder::new Source: https://docs.rs/image/latest/image/codecs/qoi/struct.QoiDecoder.html Creates a new QoiDecoder instance that reads from a given stream. This is the primary way to initialize the decoder. ```APIDOC ## QoiDecoder::new ### Description Creates a new decoder that decodes from the stream `reader`. ### Method `pub fn new(reader: R) -> ImageResult` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response - **Self** (QoiDecoder) - A new instance of QoiDecoder. ### Response Example None ``` -------------------------------- ### Get Mutable Pixel Reference (Deprecated) Source: https://docs.rs/image/latest/image/flat/type.ViewMutOfPixel.html Deprecated method for getting a mutable reference to a pixel at specified coordinates. Use `get_pixel` and `put_pixel` instead. ```rust fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut Self::Pixel ``` -------------------------------- ### Read::take Implementation Source: https://docs.rs/image/latest/image/hooks/struct.GenericReader.html Creates an adapter which will read at most `limit` bytes from it. ```rust fn take(self, limit: u64) -> Take where Self: Sized, ``` -------------------------------- ### Create AvifEncoder with Speed and Quality Source: https://docs.rs/image/latest/image/codecs/avif/struct.AvifEncoder.html Creates a new AvifEncoder with specified speed and quality settings. Speed ranges from 1 (slowest, best compression) to 10 (fastest), and quality ranges from 1 (worst) to 100 (best). ```rust pub fn new_with_speed_quality(w: W, speed: u8, quality: u8) -> Self ``` -------------------------------- ### Removing and getting the last element of a slice Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Use `split_off_last` to remove the last element from an immutable slice and get a reference to it. Returns `None` if the slice is empty. ```rust let mut slice: &[_] = &['a', 'b', 'c']; let last = slice.split_off_last().unwrap(); assert_eq!(slice, &['a', 'b']); assert_eq!(last, &'c'); ``` -------------------------------- ### AvifEncoder::new Source: https://docs.rs/image/latest/image/codecs/avif/struct.AvifEncoder.html Creates a new AvifEncoder that writes its output to the specified writer `w`. ```APIDOC ## AvifEncoder::new ### Description Creates a new encoder that writes its output to `w`. ### Method `new` ### Signature `pub fn new(w: W) -> Self` ### Parameters #### Path Parameters - **w** (W) - Description: The writer to which the encoded AVIF data will be written. ``` -------------------------------- ### Removing and getting the first element of a slice Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Use `split_off_first` to remove the first element from an immutable slice and get a reference to it. Returns `None` if the slice is empty. ```rust let mut slice: &[_] = &['a', 'b', 'c']; let first = slice.split_off_first().unwrap(); assert_eq!(slice, &['b', 'c']); assert_eq!(first, &'a'); ``` -------------------------------- ### AvifEncoder::new_with_speed_quality Source: https://docs.rs/image/latest/image/codecs/avif/struct.AvifEncoder.html Creates a new AvifEncoder with specified speed and quality settings, writing to the provided writer `w`. ```APIDOC ## AvifEncoder::new_with_speed_quality ### Description Creates a new encoder with a specified speed and quality that writes its output to `w`. `speed` accepts a value in the range 1-10, where 1 is the slowest and 10 is the fastest. Slower speeds generally yield better compression results. `quality` accepts a value in the range 1-100, where 1 is the worst and 100 is the best. ### Method `new_with_speed_quality` ### Signature `pub fn new_with_speed_quality(w: W, speed: u8, quality: u8) -> Self` ### Parameters #### Path Parameters - **w** (W) - Description: The writer to which the encoded AVIF data will be written. - **speed** (u8) - Description: The encoding speed, ranging from 1 (slowest) to 10 (fastest). - **quality** (u8) - Description: The encoding quality, ranging from 1 (worst) to 100 (best). ``` -------------------------------- ### Get Mutable Element or Subslice by Index Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Safely gets a mutable reference to an element or subslice using various index types. Returns None if the index is out of bounds. ```rust let x = &mut [0, 1, 2]; if let Some(elem) = x.get_mut(1) { *elem = 42; } assert_eq!(x, &[0, 42, 2]); ``` -------------------------------- ### Get ColorType from ExtendedColorType (color_type method) Source: https://docs.rs/image/latest/image/enum.ExtendedColorType.html Shows how to get an optional ColorType equivalent from an ExtendedColorType using the `color_type` method. Returns None if no direct equivalent exists. ```rust use image::{ColorType, ExtendedColorType}; assert_eq!(Some(ColorType::L8), ExtendedColorType::L8.color_type()); assert_eq!(None, ExtendedColorType::L1.color_type()); ``` -------------------------------- ### WebPDecoder Initialization Source: https://docs.rs/image/latest/image/codecs/webp/struct.WebPDecoder.html Initializes the WebPDecoder with a given initializer. This is an unsafe operation. ```APIDOC ## unsafe fn init(init: T::Init) -> usize ### Description Initializes the WebPDecoder with the given initializer. ### Parameters #### Path Parameters - **init** (T::Init) - Required - The initializer for the decoder. ``` -------------------------------- ### Getting the image slice with image_slice Source: https://docs.rs/image/latest/image/flat/type.ViewOfPixel.html Use `image_slice` to get a slice representing the portion of the buffer that holds sample values. The validity of coordinates is guaranteed, but the slice may contain holes. ```rust pub fn image_slice(&self) -> &[P::Subpixel] ``` -------------------------------- ### init Source: https://docs.rs/image/latest/image/buffer/struct.RowsMut.html Initializes a with the given initializer. This is an unsafe operation. ```APIDOC ## unsafe fn init(init: ::Init) -> usize ### Description Initializes a with the given initializer. This is an unsafe operation. ### Parameters - **init** (`::Init`): The initializer value. ### Returns - `usize`: The pointer to the initialized memory. ``` -------------------------------- ### Getting a reference to the inner buffer with samples Source: https://docs.rs/image/latest/image/flat/type.ViewOfPixel.html Use `samples` to get an immutable reference to the inner buffer containing pixel data. This method is intended for read-only access; the buffer cannot be reassigned or resized. ```rust pub fn samples(&self) -> &Buffer ``` -------------------------------- ### init Source: https://docs.rs/image/latest/image/buffer/struct.PixelsPar.html Initializes a with the given initializer. This is an unsafe operation. ```APIDOC ## unsafe fn init(init: ::Init) -> usize ### Description Initializes a with the given initializer. This is an unsafe operation. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method Not applicable (method call) ### Endpoint Not applicable (method call) ### Request Example Not applicable (method call) ### Response #### Success Response - **usize**: The pointer to the initialized memory. ### Response Example Not applicable (method call) ``` -------------------------------- ### Into Flat Samples Source: https://docs.rs/image/latest/image/type.GrayAlphaImage.html Returns the raw sample buffer with stride and dimension information. The buffer is laid out by colors, width, then height. ```rust pub fn into_flat_samples(self) -> FlatSamples where Container: AsRef<[P::Subpixel]>, ``` -------------------------------- ### Removing and getting the last element of a mutable slice Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Use `split_off_last_mut` to remove the last element from a mutable slice and get a mutable reference to it. Returns `None` if the slice is empty. The element can be modified in place. ```rust let mut slice: &mut [_] = &mut ['a', 'b', 'c']; let last = slice.split_off_last_mut().unwrap(); *last = 'd'; assert_eq!(slice, &['a', 'b']); assert_eq!(last, &'d'); ``` -------------------------------- ### Removing and getting the first element of a mutable slice Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Use `split_off_first_mut` to remove the first element from a mutable slice and get a mutable reference to it. Returns `None` if the slice is empty. The element can be modified in place. ```rust let mut slice: &mut [_] = &mut ['a', 'b', 'c']; let first = slice.split_off_first_mut().unwrap(); *first = 'd'; assert_eq!(slice, &['b', 'c']); assert_eq!(first, &'d'); ``` -------------------------------- ### Getting a reference to the inner sample descriptor with flat Source: https://docs.rs/image/latest/image/flat/type.ViewOfPixel.html Use `flat` to get an immutable reference to the inner sample descriptor. Modifying the buffer format through this reference is not allowed as it could invalidate accessibility invariants. ```rust pub fn flat(&self) -> &FlatSamples ``` -------------------------------- ### Clone Box with Box::clone_from_ref_in Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Demonstrates cloning a string slice into a Box with a specific allocator. Requires nightly Rust features. ```rust #![feature(clone_from_ref)] #![feature(allocator_api)] use std::alloc::System; let hello: Box = Box::clone_from_ref_in("hello", System); ``` -------------------------------- ### type_id Source: https://docs.rs/image/latest/image/flat/struct.View.html Gets the `TypeId` of the `View`. ```APIDOC ## type_id ### Description Gets the `TypeId` of `self`. ### Method `type_id(&self) -> TypeId` ### Returns - `TypeId`: The `TypeId` of the `View`. ``` -------------------------------- ### Try Clone Box with Box::try_clone_from_ref_in Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Shows how to attempt cloning a string slice into a Box with a custom allocator, returning a Result to handle allocation errors. Requires nightly Rust features. ```rust #![feature(clone_from_ref)] #![feature(allocator_api)] use std::alloc::System; let hello: Box = Box::try_clone_from_ref_in("hello", System)?; ``` -------------------------------- ### Create JpegEncoder with Default Settings Source: https://docs.rs/image/latest/image/codecs/jpeg/struct.JpegEncoder.html Creates a new JpegEncoder instance that will write its output to the provided writer `w`. Uses default quality settings. ```rust pub fn new(w: W) -> JpegEncoder ``` -------------------------------- ### type_id Source: https://docs.rs/image/latest/image/buffer/struct.PixelsPar.html Gets the `TypeId` of `self`. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method Not applicable (method call) ### Endpoint Not applicable (method call) ### Request Example Not applicable (method call) ### Response #### Success Response - **TypeId** ### Response Example Not applicable (method call) ``` -------------------------------- ### Get Mutable Pointer Range Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Use `as_mut_ptr_range` to get a half-open range of two unsafe mutable pointers spanning the slice. This is useful for interacting with foreign interfaces that expect two pointers to define a memory region. ```rust let x = &mut [1, 2, 4]; let x_ptr_range = x.as_mut_ptr_range(); // Example usage with the range would go here, demonstrating interaction with foreign interfaces. ``` -------------------------------- ### Box::new Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Allocates memory on the heap and places a value into it. This is the standard way to create a Box. ```APIDOC ## Box::new ### Description Allocates memory on the heap and then places `x` into it. This doesn’t actually allocate if `T` is zero-sized. ### Method `Box::new(x: T) -> Box` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let five = Box::new(5); ``` ### Response #### Success Response (200) Returns a `Box` containing the value `x`. #### Response Example None explicitly defined, but conceptually a boxed value. ``` -------------------------------- ### Create Monocolor Image with FlatSamples Source: https://docs.rs/image/latest/image/flat/struct.FlatSamples.html Demonstrates how to create a FlatSamples image filled with a single color. This is useful for creating a cheap, non-allocated image view. ```rust use image::{flat::FlatSamples, GenericImage, RgbImage, Rgb}; let background = Rgb([20, 20, 20]); let bg = FlatSamples::with_monocolor(&background, 200, 200); let mut image = RgbImage::new(200, 200); // paint_something(&mut image); // Reset the canvas image.copy_from(&bg.as_view().unwrap(), 0, 0); ``` -------------------------------- ### Get Pointer Range for Foreign Interface Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Use `as_ptr_range` to get a half-open range of two raw pointers spanning the slice, useful for C-style interfaces. The end pointer points one past the last element. ```rust let a = [1, 2, 3]; let x = &a[1] as *const _; let y = &5 as *const _; assert!(a.as_ptr_range().contains(&x)); assert!(!a.as_ptr_range().contains(&y)); ``` -------------------------------- ### Folding Iterator in Chunks with Initial Value Source: https://docs.rs/image/latest/image/buffer/struct.PixelsMutPar.html Splits the parallel iterator into fixed-size chunks and performs a sequential `fold` operation on each chunk, starting with a provided initial value. This is an alternative to `fold_chunks` when a specific starting value is known. ```rust fn fold_chunks_with(self, chunk_size: usize, init: T, fold_op: F) -> FoldChunksWith where T: Send + Clone, F: Fn(T, Self::Item) -> T + Send + Sync, ``` -------------------------------- ### init Source: https://docs.rs/image/latest/image/buffer/struct.EnumerateRows.html Initializes a pointer with the given initializer. This is an unsafe operation. ```APIDOC ## unsafe fn init(init: ::Init) -> usize ### Description Initializes a with the given initializer. ### Trait Implementation `impl Pointable for T` ### Source [Source link] ``` -------------------------------- ### Try Creating a Zeroed Box (fallible) Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Shows how to attempt creating a zeroed Box with uninitialized contents using `Box::try_new_zeroed`. This fallible allocation method returns a `Result` and is useful when the initial state should be zero and memory allocation might fail. ```rust #![feature(allocator_api)] let zero = Box::::try_new_zeroed()?; let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0); ``` -------------------------------- ### get Source: https://docs.rs/image/latest/image/buffer/struct.RowsMut.html Returns an iterator over a subsection of the iterator. ```APIDOC ## get ### Description Returns an iterator over a subsection of the iterator. ### Method `get` ### Parameters - `index`: A type that can index into an iterator (e.g., a range). ### Returns An iterator over the specified subsection. ``` -------------------------------- ### Getting the mutable image slice with image_mut_slice Source: https://docs.rs/image/latest/image/flat/type.ViewOfPixel.html Use `image_mut_slice` to get a mutable slice of the buffer containing sample values. This is relevant when the view was created with mutable samples. The slice may contain holes, and modifications can affect aliased samples. ```rust pub fn image_mut_slice(&mut self) -> &mut [P::Subpixel] where Buffer: AsMut<[P::Subpixel]> ``` -------------------------------- ### init Source: https://docs.rs/image/latest/image/flat/struct.View.html Initializes a with the given initializer. Returns the pointer to the initialized object. ```APIDOC ## init ### Description Initializes a with the given initializer. ### Signature `unsafe fn init(init: ::Init) -> usize` ``` -------------------------------- ### Box provide Method (Nightly) Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Provides type-based access to context intended for error reports. This is a nightly-only experimental API. ```rust fn provide<'b>(&'b self, request: &mut Request<'b>) ``` -------------------------------- ### Get UnsupportedErrorKind Source: https://docs.rs/image/latest/image/error/struct.UnsupportedError.html Returns the `UnsupportedErrorKind` associated with this error. ```rust pub fn kind(&self) -> UnsupportedErrorKind ``` -------------------------------- ### Converting RgbImage to GrayImage using DynamicImage Source: https://docs.rs/image/latest/image/enum.DynamicImage.html Demonstrates how to use DynamicImage as a converter between specific ImageBuffer instances. This example converts an RgbImage to a GrayImage. ```rust use image::{DynamicImage, GrayImage, RgbImage}; let rgb: RgbImage = RgbImage::new(10, 10); let luma: GrayImage = DynamicImage::ImageRgb8(rgb).into_luma8(); ``` -------------------------------- ### Rust is_sorted Examples Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Demonstrates the `is_sorted` method with various cases, including empty slices, sorted slices, unsorted slices, slices with one element, and slices containing NaN values. ```rust let empty: [i32; 0] = []; assert!([1, 2, 2, 9].is_sorted()); assert!(![1, 3, 2, 4].is_sorted()); assert!([0].is_sorted()); assert!(empty.is_sorted()); assert!(![0.0, 1.0, f32::NAN].is_sorted()); ``` -------------------------------- ### type_id Source: https://docs.rs/image/latest/image/flat/struct.ViewMut.html Gets the `TypeId` of `self`. This is part of the `Any` trait implementation. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method Safe ### Returns The `TypeId` of the object. ``` -------------------------------- ### Into Flat Samples Source: https://docs.rs/image/latest/image/type.Rgba32FImage.html Consumes the ImageBuffer and returns its raw sample buffer with stride and dimension information. The buffer is laid out by colors, width, then height. ```rust pub fn into_flat_samples(self) -> FlatSamples where Container: AsRef<[P::Subpixel]>, ``` -------------------------------- ### Get ImageBuffer Dimensions Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Retrieves the width and height of the image buffer. ```rust pub fn dimensions(&self) -> (u32, u32) ``` ```rust pub fn width(&self) -> u32 ``` ```rust pub fn height(&self) -> u32 ``` -------------------------------- ### try_get_i8 Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Safely gets a signed 8-bit integer from the byte stream. ```APIDOC ## try_get_i8 ### Description Gets a signed 8-bit integer from `self`. ### Method `try_get_i8` ### Parameters None ### Response #### Success Response - Returns a signed 8-bit integer (`i8`). #### Error Response - Returns `Err(TryGetError)` if a signed 8-bit integer cannot be retrieved. ``` -------------------------------- ### Try Creating a Box with Uninitialized Contents (fallible) Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Demonstrates attempting to create a Box with uninitialized contents using `Box::try_new_uninit`. This fallible allocation method returns a `Result` and is suitable for deferred initialization when memory allocation might fail. ```rust #![feature(allocator_api)] let mut five = Box::::try_new_uninit()?; // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5); ``` -------------------------------- ### Box::new_uninit Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Constructs a new Box with uninitialized contents. Useful for deferred initialization. ```APIDOC ## Box::new_uninit ### Description Constructs a new box with uninitialized contents. This is useful when you want to initialize the value later. ### Method `Box::new_uninit() -> Box>` ### Parameters None ### Request Example ```rust let mut five = Box::::new_uninit(); // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5) ``` ### Response #### Success Response (200) Returns a `Box>`. #### Response Example None explicitly defined, but conceptually a boxed uninitialized value. ``` -------------------------------- ### try_get_u8 Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Safely gets an unsigned 8-bit integer from the byte stream. ```APIDOC ## try_get_u8 ### Description Gets an unsigned 8-bit integer from `self`. ### Method `try_get_u8` ### Parameters None ### Response #### Success Response - Returns an unsigned 8-bit integer (`u8`). #### Error Response - Returns `Err(TryGetError)` if an unsigned 8-bit integer cannot be retrieved. ``` -------------------------------- ### color_space Source: https://docs.rs/image/latest/image/type.GrayImage.html Gets the Cicp encoding of this buffer’s color data. ```APIDOC ## color_space ### Description Gets the Cicp encoding of this buffer’s color data. ### Method `color_space()` ### Parameters None ### Returns `CICP` - The Cicp encoding of the buffer's color data. ``` -------------------------------- ### Create Monocolor Image with FlatSamples Source: https://docs.rs/image/latest/image/struct.FlatSamples.html Demonstrates how to create a FlatSamples image filled with a single color. This is useful for creating a cheap, non-allocated image source. ```rust use image::{flat::FlatSamples, GenericImage, RgbImage, Rgb}; let background = Rgb([20, 20, 20]); let bg = FlatSamples::with_monocolor(&background, 200, 200); let mut image = RgbImage::new(200, 200); paint_something(&mut image); // Reset the canvas image.copy_from(&bg.as_view().unwrap(), 0, 0); ``` -------------------------------- ### Create Box from Raw Pointer using Global Allocator Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Shows how to manually create a Box from a raw pointer allocated using the global allocator. Requires careful memory management and understanding of Box's memory layout. ```rust use std::alloc::{alloc, Layout}; unsafe { let ptr = alloc(Layout::new::()) as *mut i32; // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `ptr`, though for this // simple example `*ptr = 5` would have worked as well. ptr.write(5); let x = Box::from_raw(ptr); } ``` -------------------------------- ### ImageBuffer::sample_layout Source: https://docs.rs/image/latest/image/type.GrayImage.html Get the format of the buffer when viewed as a matrix of samples. ```APIDOC ## ImageBuffer::sample_layout ### Description Get the format of the buffer when viewed as a matrix of samples. ### Method `self.sample_layout() -> SampleLayout` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response `SampleLayout` #### Response Example None ``` -------------------------------- ### Any::type_id Source: https://docs.rs/image/latest/image/codecs/tiff/struct.TiffDecoder.html Gets the `TypeId` of `self`. This is a blanket implementation for any type `T` that is `'static`. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Creating a Box with a Specific Allocator Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Shows how to allocate memory and construct a Box using a custom allocator, such as std::alloc::System, via the Box::new_in function. ```rust #![feature(allocator_api)] use std::alloc::System; let five = Box::new_in(5, System); ``` -------------------------------- ### iter Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Returns an iterator over the slice, yielding items from start to end. ```APIDOC ## pub fn iter(&self) -> Iter<'_, T> ### Description Returns an iterator over the slice. The iterator yields all items from start to end. ### Examples ```rust let x = &[1, 2, 4]; let mut iterator = x.iter(); assert_eq!(iterator.next(), Some(&1)); assert_eq!(iterator.next(), Some(&2)); assert_eq!(iterator.next(), Some(&4)); assert_eq!(iterator.next(), None); ``` ``` -------------------------------- ### into_flat_samples Source: https://docs.rs/image/latest/image/type.GrayImage.html Returns the raw sample buffer with its stride and dimension information. The returned buffer is guaranteed to be well-formed and is laid out by colors, width, then height. ```APIDOC ## into_flat_samples ### Description Returns the raw sample buffer with its stride and dimension information. The returned buffer is guaranteed to be well-formed and is laid out by colors, width, then height. ### Method `into_flat_samples()` ### Parameters None ### Returns `FlatSamples` - The raw sample buffer with stride and dimension information. ``` -------------------------------- ### get_pixel_checked Source: https://docs.rs/image/latest/image/type.RgbaImage.html Gets a reference to the pixel at the specified coordinates, returning None if out of bounds. ```APIDOC ## get_pixel_checked Gets a reference to the pixel at location `(x, y)` or returns `None` if the index is out of the bounds `(width, height)`. ### Method ```rust pub fn get_pixel_checked(&self, x: u32, y: u32) -> Option<&P> where P: Pixel, Container: Deref, ``` #### Parameters - **x** (u32): The x-coordinate of the pixel. - **y** (u32): The y-coordinate of the pixel. #### Returns - `Option<&P>`: A reference to the pixel if within bounds, otherwise `None`. ``` -------------------------------- ### Create a Box with Uninitialized Contents Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Shows how to create a Box with uninitialized contents using `Box::new_uninit`. This is useful when the value will be initialized later, allowing for deferred initialization. Remember to use `unsafe` for initialization and assumption. ```rust let mut five = Box::::new_uninit(); // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5) ``` -------------------------------- ### Get Image Dimensions Source: https://docs.rs/image/latest/image/type.GrayAlphaImage.html Returns the width and height of the image buffer as a tuple. ```rust pub fn dimensions(&self) -> (u32, u32) ``` -------------------------------- ### Basic unwrap on Ok Source: https://docs.rs/image/latest/image/error/type.ImageResult.html Demonstrates the basic usage of `unwrap()` on a `Result` that is `Ok`. ```Rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` -------------------------------- ### Get Underlying Raw Buffer Source: https://docs.rs/image/latest/image/type.GrayAlphaImage.html Returns the underlying raw buffer of the ImageBuffer. ```rust pub fn into_raw(self) -> Container ``` -------------------------------- ### TryFrom for BiLevel Source: https://docs.rs/image/latest/image/imageops/colorops/struct.BiLevel.html Demonstrates the use of the `try_from` function for converting between types, including error handling. ```APIDOC ## fn try_from(value: U) -> Result>::Error> ### Description Performs the conversion. ### Method `try_from` ### Parameters * **value** (U) - The value to convert from. ### Response * **Result>::Error>** - A Result containing the converted value or an error. ``` -------------------------------- ### Open Image from Path Source: https://docs.rs/image/latest/image/fn.open.html Opens an image from a given file path. The image format is inferred from the file extension. For more advanced usage, consider using `ImageReader`. ```rust pub fn open

(path: P) -> ImageResult where P: AsRef, ``` -------------------------------- ### Get the offsets of this subimage Source: https://docs.rs/image/latest/image/struct.SubImage.html Returns the offsets of this subimage relative to the underlying image. ```rust pub fn offsets(&self) -> (u32, u32) ``` -------------------------------- ### new_uninit_in Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Constructs a new box with uninitialized contents in the provided allocator. Available on non-`no_global_oom_handling` only. ```APIDOC ## pub fn new_uninit_in(alloc: A) -> Box, A> ### Description Constructs a new box with uninitialized contents in the provided allocator. This method is available on non-`no_global_oom_handling` configurations only. ### Parameters #### Path Parameters - **alloc**: A - The allocator to use. ### Response - **Box, A>**: A Box with uninitialized contents allocated with the specified allocator. ### Examples ```rust #![feature(allocator_api)] use std::alloc::System; let mut five = Box::::new_uninit_in(System); // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5) ``` ``` -------------------------------- ### PnmDecoder::subtype Source: https://docs.rs/image/latest/image/codecs/pnm/struct.PnmDecoder.html Gets the PNM subtype based on the magic constant in the header. ```APIDOC ## PnmDecoder::subtype ### Description Get the pnm subtype, depending on the magic constant contained in the header. ### Method `subtype(&self) -> PnmSubtype` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response - **PnmSubtype** (PnmSubtype) - The subtype of the PNM image. #### Response Example None ``` -------------------------------- ### into_rgb16 Source: https://docs.rs/image/latest/image/enum.DynamicImage.html Consumes the image and returns it as a 16-bit RGB image. If the format is already correct, it's returned as is; otherwise, a copy is created. ```APIDOC ## into_rgb16 ### Description Consumes the image and returns it as a 16-bit RGB image. If the image was already the correct format, it is returned as is. Otherwise, a copy is created. ### Method Instance method (consuming) ### Parameters - **self** - Required - The DynamicImage to consume and convert. ### Returns - ImageBuffer, Vec> - An ImageBuffer representing the 16-bit RGB version of the image. ``` -------------------------------- ### deref Source: https://docs.rs/image/latest/image/buffer/struct.RowsMut.html Dereferences the given pointer to get an immutable reference. This is an unsafe operation. ```APIDOC ## unsafe fn deref<'a>(ptr: usize) -> &'a T ### Description Dereferences the given pointer to get an immutable reference. This is an unsafe operation. ### Parameters - **ptr** (`usize`): The pointer to dereference. ### Returns - `&'a T`: An immutable reference to the data at the pointer. ``` -------------------------------- ### Seek::stream_position Implementation Source: https://docs.rs/image/latest/image/hooks/struct.GenericReader.html Returns the current seek position from the start of the stream. ```rust fn stream_position(&mut self) -> Result ``` -------------------------------- ### into_rgb32f Source: https://docs.rs/image/latest/image/enum.DynamicImage.html Consumes the image and returns it as a 32-bit float RGB image. If the format is already correct, it's returned as is; otherwise, a copy is created. ```APIDOC ## into_rgb32f ### Description Consumes the image and returns it as a 32-bit float RGB image. If the image was already the correct format, it is returned as is. Otherwise, a copy is created. ### Method Instance method (consuming) ### Parameters - **self** - Required - The DynamicImage to consume and convert. ### Returns - Rgb32FImage - An Rgb32FImage representing the 32-bit float RGB version of the image. ``` -------------------------------- ### TryInto for BiLevel Source: https://docs.rs/image/latest/image/imageops/colorops/struct.BiLevel.html Illustrates the `try_into` method for converting a type into another, leveraging the `TryFrom` trait. ```APIDOC ## impl TryInto for T where U: TryFrom ### Description Performs the conversion. ### Method `try_into` ### Parameters * **self** (T) - The value to convert. ### Response * **Result>::Error>** - A Result containing the converted value or an error. ``` -------------------------------- ### Get Slice Length Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Returns the number of elements in the slice. This is a standard slice operation. ```rust let a = [1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### Try Creating Uninitialized Box with Allocator Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Use `try_new_uninit_in` to attempt creating a Box with uninitialized contents using a specified allocator. Returns a Result, yielding an error if allocation fails. This is a nightly-only API. ```rust #![feature(allocator_api)] use std::alloc.System; let mut five = Box::::try_new_uninit_in(System)?; // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5); ``` -------------------------------- ### Get Underlying Raw Buffer of ImageBuffer Source: https://docs.rs/image/latest/image/struct.ImageBuffer.html Returns the underlying raw buffer of the ImageBuffer. ```rust pub fn into_raw(self) -> Container ``` ```rust pub fn as_raw(&self) -> &Container ``` -------------------------------- ### get_int_ne Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Gets a signed n-byte integer from the byte stream in native-endian byte order. ```APIDOC ## get_int_ne ### Description Gets a signed n-byte integer from `self` in native-endian byte order. ### Method `get_int_ne` ### Parameters #### Query Parameters - **nbytes** (usize) - Required - The number of bytes to read for the signed integer. ``` -------------------------------- ### into_rgba16 Source: https://docs.rs/image/latest/image/enum.DynamicImage.html Consumes the image and returns it as a 16-bit RGBA image. If the format is already correct, it's returned as is; otherwise, a copy is created. ```APIDOC ## into_rgba16 ### Description Consumes the image and returns it as a 16-bit RGBA image. If the image was already the correct format, it is returned as is. Otherwise, a copy is created. ### Method Instance method (consuming) ### Parameters - **self** - Required - The DynamicImage to consume and convert. ### Returns - ImageBuffer, Vec> - An ImageBuffer representing the 16-bit RGBA version of the image. ``` -------------------------------- ### get_int_le Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Gets a signed n-byte integer from the byte stream in little-endian byte order. ```APIDOC ## get_int_le ### Description Gets a signed n-byte integer from `self` in little-endian byte order. ### Method `get_int_le` ### Parameters #### Query Parameters - **nbytes** (usize) - Required - The number of bytes to read for the signed integer. ``` -------------------------------- ### Box::try_new_uninit Source: https://docs.rs/image/latest/image/hooks/type.DecodingHook.html Attempts to construct a new Box with uninitialized contents on the heap, returning an error if allocation fails. Experimental API. ```APIDOC ## Box::try_new_uninit ### Description Constructs a new box with uninitialized contents on the heap, returning an error if the allocation fails. This is an experimental API. ### Method `Box::try_new_uninit() -> Result>, AllocError>` ### Parameters None ### Request Example ```rust #![feature(allocator_api)] let mut five = Box::::try_new_uninit()?; // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5); ``` ### Response #### Success Response (200) Returns `Ok(Box>)` if allocation is successful. #### Error Response (non-200) Returns `Err(AllocError)` if allocation fails. #### Response Example None explicitly defined, but conceptually a Result containing a Box or an error. ``` -------------------------------- ### into_rgba32f Source: https://docs.rs/image/latest/image/enum.DynamicImage.html Consumes the image and returns it as a 32-bit float RGBA image. If the format is already correct, it's returned as is; otherwise, a copy is created. ```APIDOC ## into_rgba32f ### Description Consumes the image and returns it as a 32-bit float RGBA image. If the image was already the correct format, it is returned as is. Otherwise, a copy is created. ### Method Instance method (consuming) ### Parameters - **self** - Required - The DynamicImage to consume and convert. ### Returns - Rgba32FImage - An Rgba32FImage representing the 32-bit float RGBA version of the image. ```