Struct x11rb::image::Image

source ·
pub struct Image<'a> { /* private fields */ }
Expand description

The description of an image.

Implementations§

source§

impl<'a> Image<'a>

source

pub fn width(&self) -> u16

The width in pixels.

source

pub fn height(&self) -> u16

The height in pixels.

source

pub fn scanline_pad(&self) -> ScanlinePad

The padding on the right side of each scanline.

Each scanline is rounded up to some multiple of the scanline_pad.

source

pub fn depth(&self) -> u8

Color depth in bits.

source

pub fn bits_per_pixel(&self) -> BitsPerPixel

Number of bits required to store one pixel.

This is always >= depth.

source

pub fn byte_order(&self) -> ImageOrder

Order in which bytes are stored in memory.

If bits_per_pixel() is smaller than 8, then this is the order in which bits are packed into bytes.

source

pub fn data(&self) -> &[u8]

Raw pixel data.

source

pub fn data_mut(&mut self) -> &mut [u8]

Mutable access to the raw pixel data.

If the Image was constructed with Cow::Borrowed-access to its pixel data, then a copy is made when this method is called.

source

pub fn new( width: u16, height: u16, scanline_pad: ScanlinePad, depth: u8, bits_per_pixel: BitsPerPixel, byte_order: ImageOrder, data: Cow<'a, [u8]> ) -> Result<Self, ParseError>

Construct a new image from existing data.

This constructs a new Image from given data without copying this data around. The other parameters describe the format that the image data is in.

See Image::allocate for a variant that allocates memory for you and Image::allocate_native for allocating an image that is in an X11 server’s native format.

§Errors

The only possible error is that data.len() is too short for an image as described by the other parameters.

source

pub fn allocate( width: u16, height: u16, scanline_pad: ScanlinePad, depth: u8, bits_per_pixel: BitsPerPixel, byte_order: ImageOrder ) -> Self

Construct a new, empty image.

This function allocates memory for a new image in the format that is described by the parameters.

See Image::new for a variant that wraps an existing in-memory image in an Image and Image::allocate_native for allocating an image that is in an X11 server’s native format.

source

pub fn allocate_native( width: u16, height: u16, depth: u8, setup: &Setup ) -> Result<Self, ParseError>

Construct a new, empty image.

This function allocates memory for a new image in the format that the X11 server expects. The image will have size widthxheight and a depth of depth.

See Image::new for a variant that wraps an existing in-memory image in an Image and Image::allocate for allocating an image that is in a more general format, not necessarily what the X11 server wants.

source

pub fn get( conn: &impl Connection, drawable: Drawable, x: i16, y: i16, width: u16, height: u16 ) -> Result<(Self, Visualid), ReplyError>

Get an image from the X11 server.

This function sends a GetImage request, waits for its response and wraps it in a new Image. The image and the corresponding visual id are returned.

The returned image contains the rectangle with top left corner (x, y) and size (width, height) of the given drawable.

source

pub fn get_from_reply( setup: &Setup, width: u16, height: u16, reply: GetImageReply ) -> Result<Self, ParseError>

Construct an Image from a GetImageReply.

This function takes a GetImageReply and wraps it in an Image. The given width and height describe the corresponding values of the GetImage request that was used to get the GetImageReply.

source

pub fn put<'c, Conn: Connection>( &self, conn: &'c Conn, drawable: Drawable, gc: Gcontext, dst_x: i16, dst_y: i16 ) -> Result<Vec<VoidCookie<'c, Conn>>, ConnectionError>

Put an image to the X11 server.

This function sends a PutImage request. This will upload this image to the given drawable to position (dst_x, dst_y).

The server’s maximum request size is honored. This means that a too large PutImage request is automatically split up into smaller pieces. Thus, if this function returns an error, the image could already be partially sent.

Before uploading, the image is translated into the server’s native format via Image::native. This may convert the image to another format, which can be slow. If you intend to upload the same image multiple times, it is likely more efficient to call Image::native once initially so that the conversion is not repeated on each upload.

source

pub fn convert( &self, scanline_pad: ScanlinePad, bits_per_pixel: BitsPerPixel, byte_order: ImageOrder ) -> Cow<'_, Self>

Convert this image into the format specified by the other parameters.

This function may need to copy the image, hence returns a Cow.

source

pub fn native(&self, setup: &Setup) -> Result<Cow<'_, Self>, ParseError>

Convert this image into the native format of the X11 server.

This function may need to copy the image, hence returns a Cow.

source

pub fn reencode<'b>( &'b self, own: PixelLayout, output: PixelLayout, setup: &Setup ) -> Result<Cow<'b, Self>, ParseError>

Reencode this image to a different pixel layout / depth.

Each pixel of this image is interpreted according to own and written to the resulting image in the format described by output.

The resulting image is always in the native format as described by setup.

source

pub fn put_pixel(&mut self, x: u16, y: u16, pixel: u32)

Set a single pixel in this image.

The pixel at position (x, y) will be set to the value pixel. pixel is truncated to this image’s Self::bits_per_pixel.

If the image was constructed from a Cow::Borrowed access to its pixel data, this causes the whole pixel data to be copied. See Image::new and Image::data_mut.

source

pub fn get_pixel(&self, x: u16, y: u16) -> u32

Get the value of a single pixel.

This function gets the value of the pixel at (x, y).

source

pub fn into_owned(self) -> Image<'static>

Get a version of this image with 'static lifetime.

If the image was constructed from a Cow::Borrowed, this clones the contained data. Otherwise, this simply returns self.

Trait Implementations§

source§

impl<'a> Clone for Image<'a>

source§

fn clone(&self) -> Image<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Image<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> PartialEq for Image<'a>

source§

fn eq(&self, other: &Image<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Eq for Image<'a>

source§

impl<'a> StructuralPartialEq for Image<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Image<'a>

§

impl<'a> RefUnwindSafe for Image<'a>

§

impl<'a> Send for Image<'a>

§

impl<'a> Sync for Image<'a>

§

impl<'a> Unpin for Image<'a>

§

impl<'a> UnwindSafe for Image<'a>

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more