Trait MapImage

Source
pub(crate) trait MapImage {
    type Pixel: PixelWithColorType;
    type Container: Deref<Target = [<Self::Pixel as Pixel>::Subpixel]> + DerefMut;
    type ViewSubBuffer: GenericImageView<Pixel: PixelWithColorType>;

    // Required methods
    fn mut_vec_view(
        &mut self,
        offset: Vec2D<u32>,
    ) -> SubBuffer<&mut ImageBuffer<Self::Pixel, Self::Container>>;
    fn vec_view(
        &self,
        offset: Vec2D<u32>,
        size: Vec2D<u32>,
    ) -> SubBuffer<&Self::ViewSubBuffer>;
    fn buffer(&self) -> &ImageBuffer<Self::Pixel, Self::Container>;

    // Provided methods
    fn export_as_png(&self) -> Result<EncodedImageExtract, Box<dyn Error>>
       where [<Self::Pixel as Pixel>::Subpixel]: EncodableLayout { ... }
    fn export_area_as_png(
        &self,
        offset: Vec2D<u32>,
        size: Vec2D<u32>,
    ) -> Result<EncodedImageExtract, Box<dyn Error>>
       where [<<Self::ViewSubBuffer as GenericImageView>::Pixel as Pixel>::Subpixel]: EncodableLayout { ... }
    fn create_snapshot<P: AsRef<Path>>(
        &self,
        path: P,
    ) -> Result<(), Box<dyn Error>>
       where [<Self::Pixel as Pixel>::Subpixel]: EncodableLayout { ... }
    fn update_area<I: GenericImageView<Pixel = Self::Pixel>>(
        &mut self,
        offset: Vec2D<u32>,
        image: &I,
    ) { ... }
}
Expand description

Trait representing operations for working with map images.

This generic trait allows manipulating and extracting data from images stored as 2D pixel buffers. It provides methods to work with sub-regions of the image, export images in PNG format, update specific areas, and more.

§Type Parameters

  • Pixel - The pixel type used by the image, which implements PixelWithColorType.
  • Container - The container storing pixel subcomponents, implementing Deref and DerefMut.
  • ViewSubBuffer - A view into a sub-region of the image, implementing GenericImageView.

Required Associated Types§

Source

type Pixel: PixelWithColorType

The type of the pixels in the image.

Source

type Container: Deref<Target = [<Self::Pixel as Pixel>::Subpixel]> + DerefMut

The container for the pixel data.

Source

type ViewSubBuffer: GenericImageView<Pixel: PixelWithColorType>

A view of a sub-region of the image.

Required Methods§

Source

fn mut_vec_view( &mut self, offset: Vec2D<u32>, ) -> SubBuffer<&mut ImageBuffer<Self::Pixel, Self::Container>>

Provides a mutable view of the image at the specified offset.

§Arguments
  • offset - The top-left corner of the requested region.
§Returns

A SubBuffer representing the specified region of the image.

Source

fn vec_view( &self, offset: Vec2D<u32>, size: Vec2D<u32>, ) -> SubBuffer<&Self::ViewSubBuffer>

Provides a view of a sub-region of the image.

§Arguments
  • offset - The top-left corner of the requested region.
  • size - The dimensions of the requested region.
§Returns

A SubBuffer representing the specified region of the image.

Source

fn buffer(&self) -> &ImageBuffer<Self::Pixel, Self::Container>

Returns a reference to the entire image buffer.

§Returns

A reference to the image buffer.

Provided Methods§

Source

fn export_as_png(&self) -> Result<EncodedImageExtract, Box<dyn Error>>
where [<Self::Pixel as Pixel>::Subpixel]: EncodableLayout,

Exports the entire image buffer as a PNG.

This method encodes the image as a PNG and returns the encoded byte array along with metadata about the image. The encoded data is stored in an EncodedImageExtract struct that contains the image’s offset, size, and encoded data.

§Returns

An EncodedImageExtract containing the offset, size, and encoded image data.

§Errors

Returns an error if the PNG encoding process fails.

Source

fn export_area_as_png( &self, offset: Vec2D<u32>, size: Vec2D<u32>, ) -> Result<EncodedImageExtract, Box<dyn Error>>
where [<<Self::ViewSubBuffer as GenericImageView>::Pixel as Pixel>::Subpixel]: EncodableLayout,

Exports a specific sub-region of the image as a PNG.

This method extracts the specified sub-region of the image, encodes it as a PNG, and returns it as an EncodedImageExtract. The sub-region to be extracted is defined by the provided offset and size.

§Arguments
  • offset - The top-left corner of the region to export.
  • size - The dimensions of the region to export, specified as a width and height.
§Returns

An EncodedImageExtract containing the offset, size, and encoded image data of the sub-region.

§Errors

Returns an error if the PNG encoding process fails.

Source

fn create_snapshot<P: AsRef<Path>>(&self, path: P) -> Result<(), Box<dyn Error>>
where [<Self::Pixel as Pixel>::Subpixel]: EncodableLayout,

Saves the current image buffer as a snapshot in PNG format.

This method writes the image’s content to the file at the specified path in PNG format.

§Arguments
  • path - The file path where the snapshot should be saved.
§Returns

Returns Ok(()) if the save operation is successful. Returns an error if the save process fails.

Source

fn update_area<I: GenericImageView<Pixel = Self::Pixel>>( &mut self, offset: Vec2D<u32>, image: &I, )

Updates a specific sub-region of the image with the given data.

This method copies the content of image into the corresponding sub-region of the current image buffer, starting from the specified offset.

§Arguments
  • offset - The top-left corner of the target sub-region to update.
  • image - The new image data to copy into the target sub-region.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§