pub struct Image<'a> { /* private fields */ }
Expand description
The description of an image.
Implementations§
source§impl<'a> Image<'a>
impl<'a> Image<'a>
sourcepub fn scanline_pad(&self) -> ScanlinePad
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
.
sourcepub fn bits_per_pixel(&self) -> BitsPerPixel
pub fn bits_per_pixel(&self) -> BitsPerPixel
Number of bits required to store one pixel.
This is always >= depth
.
sourcepub fn byte_order(&self) -> ImageOrder
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.
sourcepub fn data_mut(&mut self) -> &mut [u8] ⓘ
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.
sourcepub 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>
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.
sourcepub fn allocate(
width: u16,
height: u16,
scanline_pad: ScanlinePad,
depth: u8,
bits_per_pixel: BitsPerPixel,
byte_order: ImageOrder
) -> Self
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.
sourcepub fn allocate_native(
width: u16,
height: u16,
depth: u8,
setup: &Setup
) -> Result<Self, ParseError>
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 width
xheight
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.
sourcepub fn get(
conn: &impl Connection,
drawable: Drawable,
x: i16,
y: i16,
width: u16,
height: u16
) -> Result<(Self, Visualid), ReplyError>
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
.
sourcepub fn get_from_reply(
setup: &Setup,
width: u16,
height: u16,
reply: GetImageReply
) -> Result<Self, ParseError>
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
.
sourcepub 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>
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.
sourcepub fn convert(
&self,
scanline_pad: ScanlinePad,
bits_per_pixel: BitsPerPixel,
byte_order: ImageOrder
) -> Cow<'_, Self>
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
.
sourcepub fn native(&self, setup: &Setup) -> Result<Cow<'_, Self>, ParseError>
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
.
sourcepub fn reencode<'b>(
&'b self,
own: PixelLayout,
output: PixelLayout,
setup: &Setup
) -> Result<Cow<'b, Self>, ParseError>
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
.
sourcepub fn put_pixel(&mut self, x: u16, y: u16, pixel: u32)
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
.
sourcepub fn get_pixel(&self, x: u16, y: u16) -> u32
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)
.
sourcepub fn into_owned(self) -> Image<'static>
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
.