Struct imagequant::Image

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

Describes image dimensions and pixels for the library

Create one using Attributes::new_image().

All images are internally in the RGBA format.

Implementations§

source§

impl<'pixels> Image<'pixels>

source

pub fn new<VecRGBA>( attr: &Attributes, pixels: VecRGBA, width: usize, height: usize, gamma: f64 ) -> Result<Self, Error>
where VecRGBA: Into<Box<[RGBA]>>,

Makes an image from RGBA pixels.

See the rgb and bytemuck crates for making [RGBA] slices from [u8] slices.

The pixels argument can be Vec<RGBA>, or Box<[RGBA]> or &[RGBA].

If you want to supply RGB or ARGB pixels, convert them to RGBA first, or use Image::new_fn to supply your own pixel-swapping function.

Use 0. for gamma if the image is sRGB (most images are).

source

pub fn new_borrowed( attr: &Attributes, pixels: &'pixels [RGBA], width: usize, height: usize, gamma: f64 ) -> Result<Self, Error>

Describe dimensions of a slice of RGBA pixels.

Same as Image::new, except it doesn’t copy the pixels, but holds a temporary reference instead.

If you want to supply RGB or ARGB pixels, use Image::new_fn to supply your own pixel-swapping function.

See the rgb and bytemuck crates for making [RGBA] slices from [u8] slices.

Use 0. for gamma if the image is sRGB (most images are).

source

pub unsafe fn new_fn<F: 'pixels + Fn(&mut [MaybeUninit<RGBA>], usize) + Send + Sync>( attr: &Attributes, convert_row_fn: F, width: usize, height: usize, gamma: f64 ) -> Result<Self, Error>

Generate rows on demand using a callback function.

The callback function should be cheap (e.g. just byte-swap pixels). The parameters are: line of RGBA pixels (slice’s len is equal to image width), and row number (0-indexed). The callback will be called multiple times per row. May be called from multiple threads at once.

Use 0. for gamma if the image is sRGB (most images are).

§Safety

This function is marked as unsafe, because the callback function MUST initialize the entire row (call write on every MaybeUninit pixel).

source

pub fn set_importance_map( &mut self, map: impl Into<Box<[u8]>> ) -> Result<(), Error>

Set which pixels are more important (and more likely to get a palette entry)

The map must be width×height pixels large. Higher numbers = more important.

source

pub fn set_background(&mut self, background: Self) -> Result<(), Error>

Remap pixels assuming they will be displayed on this background. This is designed for GIF’s “keep” mode.

Pixels that match the background color will be made transparent if there’s a fully transparent color available in the palette.

The background image’s pixels must outlive this image.

source

pub fn add_fixed_color(&mut self, color: RGBA) -> Result<(), Error>

Reserves a color in the output palette created from this image. It behaves as if the given color was used in the image and was very important.

The RGB values are assumed to have the same gamma as the image.

It must be called before the image is quantized.

Returns error if more than 256 colors are added. If image is quantized to fewer colors than the number of fixed colors added, then excess fixed colors will be ignored.

source

pub fn width(&self) -> usize

Width of the image in pixels

source

pub fn height(&self) -> usize

Height of the image in pixels

source

pub fn new_stride_borrowed( attr: &Attributes, pixels: &'pixels [RGBA], width: usize, height: usize, stride: usize, gamma: f64 ) -> Result<Self, Error>

Stride is in pixels. Allows defining regions of larger images or images with padding without copying. The stride is in pixels.

Otherwise the same as Image::new_borrowed.

source

pub fn new_stride<VecRGBA>( attr: &Attributes, pixels: VecRGBA, width: usize, height: usize, stride: usize, gamma: f64 ) -> Result<Image<'static>, Error>
where VecRGBA: Into<Box<[RGBA]>>,

Create new image by copying pixels to an internal buffer, so that it makes a self-contained type.

The pixels argument can be Vec<RGBA>, or Box<[RGBA]> or &[RGBA].

Otherwise the same as Image::new_stride_borrowed.

Trait Implementations§

source§

impl<'pixels> Clone for Image<'pixels>

source§

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

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

Auto Trait Implementations§

§

impl<'pixels> Freeze for Image<'pixels>

§

impl<'pixels> !RefUnwindSafe for Image<'pixels>

§

impl<'pixels> Send for Image<'pixels>

§

impl<'pixels> Sync for Image<'pixels>

§

impl<'pixels> Unpin for Image<'pixels>

§

impl<'pixels> !UnwindSafe for Image<'pixels>

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

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