Struct imagequant::Attributes

source ·
pub struct Attributes { /* private fields */ }
Expand description

Starting point and settings for the quantization process

Implementations§

source§

impl Attributes

source

pub fn new() -> Self

New handle for library configuration

See also Attributes::new_image()

source

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

Make an image from RGBA pixels.

The pixels argument can be Vec<RGBA>, or Box<[RGBA]> or &[RGBA]. See Attributes::new_image_borrowed for a non-copying alternative.

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

source

pub fn quantize( &self, image: &mut Image<'_> ) -> Result<QuantizationResult, Error>

Generate palette for the image

source

pub fn set_max_colors(&mut self, colors: u32) -> Result<(), Error>

It’s better to use set_quality()

source

pub fn set_quality(&mut self, minimum: u8, target: u8) -> Result<(), Error>

Range 0-100, roughly like JPEG.

If the minimum quality can’t be met, the quantization will be aborted with an error.

Default is min 0, max 100, which means best effort, and never aborts the process.

If max is less than 100, the library will try to use fewer colors. Images with fewer colors are not always smaller, due to increased dithering it causes.

source

pub fn set_speed(&mut self, value: i32) -> Result<(), Error>

1-10.

Faster speeds generate images of lower quality, but may be useful for real-time generation of images.

The default is 4.

source

pub fn set_min_posterization(&mut self, value: u8) -> Result<(), Error>

Number of least significant bits to ignore.

Useful for generating palettes for VGA, 15-bit textures, or other retro platforms.

source

pub fn min_posterization(&self) -> u8

Returns number of bits of precision truncated

source

pub fn speed(&self) -> u32

Return currently set speed/quality trade-off setting

source

pub fn max_colors(&self) -> u32

Return max number of colors set

source

pub fn quality(&self) -> (u8, u8)

Reads values set with set_quality

source

pub fn new_image_borrowed<'pixels>( &self, bitmap: &'pixels [RGBA], width: usize, height: usize, gamma: f64 ) -> Result<Image<'pixels>, Error>

Describe dimensions of a slice of RGBA pixels

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

source

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

Like new_image_stride_borrowed, but makes a copy of the pixels.

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

source

pub fn set_log_callback<F: Fn(&Self, &str) + Send + Sync + 'static>( &mut self, callback: F )

Set callback function to be called every time the library wants to print a message.

To share data with the callback, use Arc or Atomic* types and move || closures.

source

pub fn set_log_flush_callback<F: Fn(&Self) + Send + Sync + 'static>( &mut self, callback: F )

Callback for flushing output (if you buffer messages, that’s the time to flush those buffers)

source

pub fn set_progress_callback<F: Fn(f32) -> ControlFlow + Send + Sync + 'static>( &mut self, callback: F )

Set callback function to be called every time the library makes a progress. It can be used to cancel operation early.

To share data with the callback, use Arc or Atomic* types and move || closures.

source

pub fn set_last_index_transparent(&mut self, is_last: bool)

Move transparent color to the last entry in the palette

This is less efficient for PNG, but required by some broken software

Trait Implementations§

source§

impl Clone for Attributes

source§

fn clone(&self) -> Attributes

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 Default for Attributes

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Drop for Attributes

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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.