ImageCell

Struct ImageCell 

Source
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>

Source

pub fn new(image: Image<P, U>) -> Self

Source

pub fn into_inner(self) -> Image<P, U>

Returns the underlying image.

Source

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]));

Methods from Deref<Target = Image<P, U>>§

Source

pub fn capacity(&self) -> usize

Returns the capacity of the underlying image’s data buffer.

Trait Implementations§

Source§

impl<P: Pixel, U: GenericImage<Pixel = P>> Deref for ImageCell<P, U>

Source§

type Target = Image<P, U>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<P: Pixel, U: GenericImage<Pixel = P>> Send for ImageCell<P, U>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.