pub struct ImageCell<P: Pixel, U: GenericImage<Pixel = P>> { /* private fields */ }Expand description
A struct that allows multible mutable references to an underlying image’s data buffer. This is an unsafe struct and should only be used when no two items are trying to change the same place in the underlying image’s data buffer. This struct is used to allow multible threads to write to the same image at the same time.
Implementations§
Source§impl<P: Pixel, U: GenericImage<Pixel = P>> ImageCell<P, U>
impl<P: Pixel, U: GenericImage<Pixel = P>> ImageCell<P, U>
pub fn new(image: Image<P, U>) -> Self
Sourcepub fn into_inner(self) -> Image<P, U>
pub fn into_inner(self) -> Image<P, U>
Returns the underlying image.
Sourcepub unsafe fn request_handout(&self, x: u32, y: u32) -> Handout<'_, P, U>
pub unsafe fn request_handout(&self, x: u32, y: u32) -> Handout<'_, P, U>
Requests a handout at the given coordinates of the undelrying image. Can be be used to write to an underlying image buffer across threads without a mutable reference to the underlying image.
§Safety
This function is unsafe because it does not implement any thread safety via locks or anything else. It is up to the caller to ensure that no two threads are trying to write to the same place in the underlying image’s data buffer.
§Arguments
x- The x coordinate of the pixel to request a handout for.y- The y coordinate of the pixel to request a handout for.
§Returns
A handout that can be used to write to the underlying image’s data buffer.
§Example
use image_merger::{Rgb, raw::ImageCell, Image};
use image::ImageBuffer;
let buf: ImageBuffer<Rgb<u8>, Vec<u8>> = ImageBuffer::new(100, 100);
let cell = ImageCell::new(Image::from(buf));
let mut handout = unsafe { cell.request_handout(0, 0) };
handout.put_pixel(Rgb([255, 255, 255]));Trait Implementations§
impl<P: Pixel, U: GenericImage<Pixel = P>> Send for ImageCell<P, U>
impl<P: Pixel, U: GenericImage<Pixel = P>> Sync for ImageCell<P, U>
Auto Trait Implementations§
impl<P, U> !Freeze for ImageCell<P, U>
impl<P, U> !RefUnwindSafe for ImageCell<P, U>
impl<P, U> Unpin for ImageCell<P, U>where
U: Unpin,
impl<P, U> UnwindSafe for ImageCell<P, U>where
U: UnwindSafe,
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more