Struct imagequant::Attributes
source · pub struct Attributes { /* private fields */ }
Expand description
Starting point and settings for the quantization process
Implementations§
source§impl Attributes
impl Attributes
sourcepub fn new() -> Self
pub fn new() -> Self
New handle for library configuration
See also Attributes::new_image()
sourcepub fn new_image<VecRGBA>(
&self,
pixels: VecRGBA,
width: usize,
height: usize,
gamma: f64,
) -> Result<Image<'static>, Error>
pub fn new_image<VecRGBA>( &self, pixels: VecRGBA, width: usize, height: usize, gamma: f64, ) -> Result<Image<'static>, Error>
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).
sourcepub fn quantize(
&self,
image: &mut Image<'_>,
) -> Result<QuantizationResult, Error>
pub fn quantize( &self, image: &mut Image<'_>, ) -> Result<QuantizationResult, Error>
Generate palette for the image
sourcepub fn set_max_colors(&mut self, colors: u32) -> Result<(), Error>
pub fn set_max_colors(&mut self, colors: u32) -> Result<(), Error>
It’s better to use set_quality()
sourcepub fn set_quality(&mut self, minimum: u8, target: u8) -> Result<(), Error>
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.
sourcepub fn set_speed(&mut self, value: i32) -> Result<(), Error>
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.
sourcepub fn set_min_posterization(&mut self, value: u8) -> Result<(), Error>
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.
sourcepub fn min_posterization(&self) -> u8
pub fn min_posterization(&self) -> u8
Returns number of bits of precision truncated
sourcepub fn max_colors(&self) -> u32
pub fn max_colors(&self) -> u32
Return max number of colors set
sourcepub fn new_image_borrowed<'pixels>(
&self,
bitmap: &'pixels [RGBA],
width: usize,
height: usize,
gamma: f64,
) -> Result<Image<'pixels>, Error>
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).
sourcepub fn new_image_stride<VecRGBA>(
&self,
pixels: VecRGBA,
width: usize,
height: usize,
stride: usize,
gamma: f64,
) -> Result<Image<'static>, Error>
pub fn new_image_stride<VecRGBA>( &self, pixels: VecRGBA, width: usize, height: usize, stride: usize, gamma: f64, ) -> Result<Image<'static>, Error>
Like new_image_stride_borrowed
, but makes a copy of the pixels.
The pixels
argument can be Vec<RGBA>
, or Box<[RGBA]>
or &[RGBA]
.
sourcepub fn set_log_callback<F: Fn(&Self, &str) + Send + Sync + 'static>(
&mut self,
callback: F,
)
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.
sourcepub fn set_log_flush_callback<F: Fn(&Self) + Send + Sync + 'static>(
&mut self,
callback: F,
)
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)
sourcepub fn set_progress_callback<F: Fn(f32) -> ControlFlow + Send + Sync + 'static>(
&mut self,
callback: F,
)
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.
sourcepub fn set_last_index_transparent(&mut self, is_last: bool)
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
impl Clone for Attributes
source§fn clone(&self) -> Attributes
fn clone(&self) -> Attributes
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Default for Attributes
impl Default for Attributes
Auto Trait Implementations§
impl Freeze for Attributes
impl !RefUnwindSafe for Attributes
impl Send for Attributes
impl Sync for Attributes
impl Unpin for Attributes
impl !UnwindSafe for Attributes
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)