Struct kodak::Image

source · []
pub struct Image { /* private fields */ }
Expand description

The Image struct is at the heart of Kodak. You’ll be using functions on this 95% of the time.

Note that the maximum image size is 2^32 - 1 by 2^32 - 1 pixels. This limit was chosen because it is also the maximum of the PNG format.

Implementations

Creates a new blank image.

The default colour used is black.

Arguments
  • dimension - the dimensions of the image to be created
Returns

The newly created image.

Returns the dimensions of the image.

Returns the entire image as a region.

Tries to look up the colour of a specific pixel; returns an Err<&str> if the location is out of bounds and an Ok if not.

Fill the entire image with a given colour.

Arguments
  • colour: the colour to fill with.
Examples
let img = Image::blank(30, 20).fill(Colour::WHITE);
assert_eq!(img.pixels[0], Colour::WHITE);

Fills a region.

Crop a region out of the image and return it. This method is mainly used internally and panics; the safer crop() should be used instead.

The corner from which to crop is assumed to be the top left corner.

Panics
  • if the corner from which to crop is outside of the image,
  • if the cropped image would reach outside of the image (by specifying new dimensions which are too large).

Crop a region out of the image and return it. This method (unlike crop_unclamped()) will adjust the size of the region if it is too big. It will return an Err<&str> if the corner to begin with falls outside of the image.

Arguments
  • region - the region to crop out (inclusive).
Examples
let img = Image::blank( Dim { w: 20, h: 30 } )
    .crop( Region { l: Loc { x: 10, y: 10 }, d: Dim { w: 10, h: 10 } } )
    .unwrap();
assert_eq!(img.width, 10);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.